vb.net 類庫中如何使用webservice

backbone601發表於2015-08-10

環境:windows8+vs2010+vb.net+winform

 

類庫中引用 webservice 服務後,直接呼叫時會碰到如下的錯誤:

 

在 ServiceModel 客戶端配置部分中,找不到引用協定“WebServiceForSanYou.TosServiceSoap”的預設終結點元素。這可能是因為未找到應用程式的配置檔案,或者是因為

 

解決方案:

 

1)在類庫裡引用服務時,會產生 app.config 檔案

 

2)將上述檔案中如下部分複製到 主程式的 app.config 中。(注意 endpoint 節只保留一個)

 

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="TosServiceSoap" />
            </basicHttpBinding>
            <customBinding>
                <binding name="TosServiceSoap12">
                    <textMessageEncoding messageVersion="Soap12" />
                    <httpTransport />
                </binding>
            </customBinding>
        </bindings>
        <client>
            <endpoint address="http://tos.tytus.com.cn:23458/webService/tosservice.asmx"
                binding="basicHttpBinding" bindingConfiguration="TosServiceSoap"
                contract="WebServiceForSanYou.TosServiceSoap" name="TosServiceSoap" />
            <!--<endpoint address="http://tos.tytus.com.cn:23458/webService/tosservice.asmx"
                binding="customBinding" bindingConfiguration="TosServiceSoap12"
                contract="WebServiceForSanYou.TosServiceSoap" name="TosServiceSoap12" />-->
        </client>
    </system.serviceModel>

相關文章