Soap webservice returns “The content type application/soap+xml; charset=UTF-8”

女生的网名这么多〃 提交于 2020-04-30 08:41:51

问题


I'am trying to communicate with some SOAP webservice (which is from Joomla) I keep getting this error:

The content type application/soap+xml; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 330 bytes of the response were: '<?xml version="1.0" encoding="UTF-8"?>
                    <SOAP-ENV:Envelope
                        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
                        <SOAP-ENV:Body>
                            <SOAP-ENV:Fault>
                                <faultcode>SOAP-ENV:Server</faultcode>
                                <faultstring>401 Unauthorized</faultstring>
                            </SOAP-ENV:Fault>
                        </'.

I have tried every binding I can think of but I am yet to figure out what is causing my problems

Code:

            using (NewPconradesenTest.Tag.siteredshopbtag100Client client = new Tag.siteredshopbtag100Client())
        {
            client.ClientCredentials.UserName.UserName = username;
            client.ClientCredentials.UserName.Password = password;
            client.Open();
            Console.WriteLine("\nClient State: " + client.State.ToString());

            try
            {
                Tag.readList_filters filter = new Tag.readList_filters();
                var result = client.readList(0, 99, emptyString, filter, emptyString, emptyString, language);

            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message.ToString());
                Console.WriteLine(e.InnerException.ToString());
                Console.WriteLine(e.Source.ToString());
                //Console.WriteLine(e.HResult.ToString());
                //Console.WriteLine(e.StackTrace.ToString());
            }
        }

App.config:

<bindings>
    <customBinding>
        <binding name="site.redshopb-tag.1.0.0">
            <textMessageEncoding messageVersion="Soap11" />
            <httpTransport/>
        </binding>
    </customBinding>
</bindings>
<client>
    <endpoint address="XXXXXXXXXXXXXXXXXXXXXXX;view=tag&amp;api=soap"
        binding="customBinding" bindingConfiguration="site.redshopb-tag.1.0.0"
        contract="Tag.siteredshopbtag100" name="site.redshopb-tag.1.0.0_Soap" />
</client>

I hope somebody can help me, Thanks for your time


回答1:


I ended up sending my code to the webservice guys, and the ended up saving me.

        using (webservice.client request = new webservice.client ())
        {
            using (OperationContextScope scope = new OperationContextScope(request.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(header);

                HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
                httpRequestProperty.Headers.Add("Authorization", "Basic " + this.Base64Encode(Program.username + ":" + Program.password));
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;

                var result = request.readList(0, 100, null, filter, null, null, Program.language);
                this.printOutArrays(result);
            }
        }


来源:https://stackoverflow.com/questions/32204254/soap-webservice-returns-the-content-type-application-soapxml-charset-utf-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!