Soap webservice返回"内容类型application / soap + xml;字符集= UTF-8"

时间:2015-08-25 12:38:18

标签: xml web-services wcf soap joomla

我正在尝试与一些SOAP Web服务(来自Joomla)进行通信 我一直收到这个错误:

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>
                        </'.

我已经尝试了我能想到的每一个约束,但我还没弄清楚是什么导致了我的问题

代码:

            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>

我希望有人可以帮助我,谢谢你的时间

1 个答案:

答案 0 :(得分:0)

我最终将我的代码发送给了网络服务人员,结果救了我。

        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);
            }
        }