C#使⽤WebService
⼀、新建webservice
1. 新建项⽬→asp Web服务应⽤程序
2. 或者在现有项⽬中点击右键新建web服务程序asmx
3.
4.
5. 只要在webservice类⾥⾯的⽅法标注为【WebMethod】就成为别⼈可以调的⽅法
6.
7. 如果要返回DataTable
8. 只要 DataTable.TableName 不为空, 即可返回
否则不⾏.
9. ⼆、webservice调⽤
引⽤之后直接就可以使⽤⾥⾯的⽅法了命名空间类名 client=new 类; client.⽅法()
常⽤错误
①⽆法加载协定为“ServiceReference1.InterfaceSoap”的终结点配置部分,因为到了该协定的多个终结点配置。请按名称指⽰⾸选的
如果出现以上错误是因为第⼀次引⽤webservice的时候已经在webconfig⾥⾯产⽣了<endpoint>配置节点,⾸次运⾏的时候⼜⼀次加了那么⼀个配置节点重复了,需要⼿动删除⼀个节点原因是在fig ⽂件中多次引⽤了“添加外部引⽤”
<client>
<endpoint address="218.90.168.115:8000/PJSDFacade/PJSD/Interface.asmx"
binding="basicHttpBinding" bindingConfiguration="InterfaceSoap"
contract="ServiceReference1.InterfaceSoap" name="InterfaceSoap" />
<!-- 下⾯节点删除-->
<endpoint address="218.90.168.115:8000/PJSDFacade/PJSD/Interface.asmx"
binding="customBinding" bindingConfiguration="InterfaceSoap12"
contract="ServiceReference1.InterfaceSoap" name="InterfaceSoap12" />
</client>
所以删掉⼀个节点既可(如查引⽤的是WebServiceSoap,删掉WebServiceSoap1的有关节点,反之~)
也可以在页⾯引⽤的时候指定bindingConfiguration名字:
如:ServiceReference.WebServiceSoap web = new WebServiceSoapClient("InterfaceSoap");
在调⽤webservice返回数据的时候,出现以下错误:
已超过传⼊消息(65536)的最⼤消息⼤⼩配额。若要增加配额,请使⽤相应绑定元素上的 MaxReceivedMessageSize 属性
这个就需要在调⽤webservice的解决⽅案中,在fig或者fig中配置⼀下:注意红⾊字体为哪个节点下加的哪些配置。
<system.serviceModel>
<bindings >
<basicHttpBinding>
<binding name="InterfaceSoap"maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
</basicHttpBinding>
<customBinding>
调用webservice服务<binding name="InterfaceSoap12" >
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="218.90.168.115:8000/PJSDFacade/PJSD/Interface.asmx"
binding="basicHttpBinding" bindingConfiguration="InterfaceSoap"
contract="ServiceReference.InterfaceSoap" name="InterfaceSoap" />
</client>
</system.serviceModel>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论