简体   繁体   中英

Could not find default endpoint element that references contract.in the ServiceModel client configuration section

I have added a service reference named http://192.168.5.180:8080/intg/CrmWebService.asmx . with name CrmWebProxy.

Below are the line of code.

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);

I get the above mentioned error.But if I test it in sample application it runs perfectly.

Any help.

It looks like you haven't copied the configuration entry for the web service. Without it, you cannot invoke a web service.

When you add a service reference in your project, configuration entry for your web service is added in your app.config of web.config file. A sample configuration may look like this. You need to copy that to your project configuration file.

<?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>

Note: this is only a sample file. You need to find something like this from your project that works (in console) and copy that entry to the app.config in whatever other project you are using the service in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM