2011-12-24 33 views
1

我已添加名爲http://192.168.5.180:8080/intg/CrmWebService.asmx的服務參考。 ,名稱爲CrmWebProxy。在ServiceModel客戶端配置部分中找不到引用contract.的默認端點元素

下面是代碼行。

Microsoft.Crm.Accelerator.Cca.SampleServices.CrmWebService.CustomerRecord[] resultWebService = new Microsoft.Crm.Accelerator.Cca.SampleServices.CrmWebService.CustomerRecord[3]; 
Microsoft.Crm.Accelerator.Cca.SampleServices.CrmWebService.CRMWebServiceSoapClient client = new Microsoft.Crm.Accelerator.Cca.SampleServices.CrmWebService.CRMWebServiceSoapClient(); 
resultWebService = client.GetCustomerData(firstName, lastName, phoneNumber, email, accountName, accountNo, maxRecords); 

我得到了上面提到的error.But,如果我在示例應用程序中測試它運行完美。

任何幫助。

+0

我在WPF應用程序中使用Web服務。 – 2011-12-24 11:42:53

回答

5

看起來您並未複製Web服務的配置條目。沒有它,你不能調用Web服務。

在項目中添加服務引用時,Web服務的配置條目將添加到web.config文件的app.config中。示例配置可能如下所示。您需要將其複製到您的項目配置文件中。

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <basicHttpBinding> 
       <binding name="GlobalWeatherSoap" closeTimeout="00:01:00" openTimeout="00:01:00" 
        receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" 
        bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
        maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
        useDefaultWebProxy="true"> 
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        <security mode="None"> 
         <transport clientCredentialType="None" proxyCredentialType="None" 
          realm="" /> 
         <message clientCredentialType="UserName" algorithmSuite="Default" /> 
        </security> 
       </binding> 
      </basicHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://www.webservicex.com/globalweather.asmx" 
       binding="basicHttpBinding" bindingConfiguration="GlobalWeatherSoap" 
       contract="ServiceReference1.GlobalWeatherSoap" name="GlobalWeatherSoap" /> 
     </client> 
    </system.serviceModel> 
</configuration> 

注意:這只是一個示例文件。你需要從你的工程中找到這樣的東西(在控制檯中),並將該條目複製到你正在使用服務的任何其他項目中的app.config。

+0

嗨,Tomislav,我是WPF新手,因此你可以詳細說明一下。我在Console應用程序中測試過它,它工作的很好。 謝謝。 – 2011-12-24 11:44:15

+1

這不是WPF特有的,它是.NET如何與Web服務一起工作的。看我的編輯。 – 2011-12-24 11:49:17

相關問題