没有代理的SOAP(ASMX)Web服务客户端

时间:2014-10-28 12:45:06

标签: c# web-services wcf soap channelfactory

我有两个客户。第一个是自动生成的代理,如下所示:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.18408")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="Service1", Namespace="http://tempuri.org/")]
public partial class Service1 : System.Web.Services.Protocols.SoapHttpClientProtocol {
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/Get", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    public Data[] Get(int x) {
        object[] results = this.Invoke("InMotion_Wholesaler_FromTimestampAdv", new object[] {
                    login,
                    password,
                    timestamp});
        return ((InmWholesaler[])(results[0]));
    }

它工作并返回包含元素的数据列表。

第二个是这样的:

[ServiceContract]
[WebServiceBinding(Name = "Service1", Namespace = "http://tempuri.org/")]
public interface IService1
{
    [OperationContract]
    [SoapDocumentMethod(
        "http://tempuri.org/Get",
        RequestNamespace = "http://tempuri.org/",
        ResponseNamespace = "http://tempuri.org/",
        Use = System.Web.Services.Description.SoapBindingUse.Literal,
        ParameterStyle = SoapParameterStyle.Wrapped)]
    Data[] Get(int x);
}

    private IService1 Service1
    {
        get
        {
            var soap12Binding = new CustomBinding(
                new TextMessageEncodingBindingElement(MessageVersion.Soap12, Encoding.UTF8)
                {
                    ReaderQuotas = new XmlDictionaryReaderQuotas
                    {
                        MaxArrayLength = int.MaxValue,
                        MaxBytesPerRead = int.MaxValue,
                        MaxDepth = int.MaxValue,
                        MaxNameTableCharCount = int.MaxValue,
                        MaxStringContentLength = int.MaxValue
                    },
                },
                new HttpTransportBindingElement
                {
                    MaxReceivedMessageSize = int.MaxValue
                });

            var channelFactory = new ChannelFactory<IService1>(soap12Binding, new EndpointAddress(url));

            return channelFactory.CreateChannel();
        }
    }

此客户端返回空列表(非空)。

我可以通过ChannelFactory创建客户端吗?我的错是什么?

0 个答案:

没有答案