2011-12-24 63 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

相关问题