webservices设置web.config供远程调用

发布时间 2024-01-08 11:24:32作者: IT苦行僧-QF

在网站的解决方案的下方找到web.config

复制代码
<system.web>  
    <webServices>  
      <protocols>  
        <add name="HttpGet"/>  
        <add name="HttpPost"/>  
      </protocols>  
    </webServices>    
<system.web>
复制代码

 2.无法加载协定为“ServiceReference1.xxxxxx”的终结点配置部分,因为找到了该协定的多个终结点配置。请按名称指示首选的终结点配置部分。

原因是在web.config 文件中多次引用了“添加外部引用”

复制代码
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WebServiceSoap" />
<binding name="WebServiceSoap1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://10.29.68.32/WebService.asmx" binding="basicHttpBinding"
bindingConfiguration="WebServiceSoap" contract="ServiceReference.WebServiceSoap"
name="WebServiceSoap" />
<endpoint address="http://10.29.68.32/WebService.asmx" binding="basicHttpBinding"
bindingConfiguration="WebServiceSoap1" contract="ServiceReference.WebServiceSoap"
name="WebServiceSoap1" />
</client>
</system.serviceModel>
复制代码

 

所以删掉一个节点既可(如查引用的是WebServiceSoap,删掉WebServiceSoap1的有关节点,反之~)

也可以在页面引用的时候指定bindingConfiguration名字:

如:ServiceReference.WebServiceSoap web = new WebServiceSoapClient("WebServiceSoap");

3.

在调用webservice返回数据的时候, 出现以下错误:

已超过传入消息(65536)的最大消息大小配额。若要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性

这个就需要在调用webservice的解决方案中,在web.config或者app.config中配置一下:注意红色字体为哪个节点下加的哪些配置。

复制代码
<system.serviceModel>
        <bindings >
              <basicHttpBinding>
                    <binding name="InterfaceSoap" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"   />
              </basicHttpBinding>
              <customBinding>
                    <binding name="InterfaceSoap12"   >
                          <textMessageEncoding messageVersion="Soap12" />
                          <httpTransport />
                    </binding>
              </customBinding>
        </bindings>
        <client>
              <endpoint address="http://218.90.168.115:8000/PJSDFacade/PJSD/Interface.asmx"
                    binding="basicHttpBinding" bindingConfiguration="InterfaceSoap"
                    contract="ServiceReference.InterfaceSoap" name="InterfaceSoap" />
             
        </client>
    </system.serviceModel>