Invalid operation Exception while instantiating object of asmx web service - c#

I am trying to incorporate .asmx web service in my application.
For this I
1. created a Class library project.
2. Added service reference with the given wsdl
3. An app.Config was automatically created. The app.config that is
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="UploadWebServiceSoap" 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>
<customBinding>
<binding name="UploadWebServiceSoap12">
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Soap12" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<httpTransport manualAddressing="false" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
useDefaultWebProxy="true" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:xxxx/xxx/UploadWebService.asmx"
binding="basicHttpBinding" bindingConfiguration="UploadWebServiceSoap"
contract="ServiceReference1.UploadWebServiceSoap" name="UploadWebServiceSoap" />
<endpoint address="http://localhost:xxxx/xxx/UploadWebService.asmx"
binding="customBinding" bindingConfiguration="UploadWebServiceSoap12"
contract="ServiceReference1.UploadWebServiceSoap" name="UploadWebServiceSoap12" />
</client>
</system.serviceModel>
After all the set up, I tried calling the methods in web-service in my function.
UploadWebServiceSoapClient dpcClient = new UploadWebServiceSoapClient();
This is where is get an error
Could not find default endpoint element that references contract 'ServiceReference1.UploadWebServiceSoap' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
Can anyone please tell me why I am getting this error. Also, I understand the binding created basicHttpBinding but what is and an endpoint for the same was created

It looks as if you've created service reference multiple times. First you created ServiceReference1 and then DPCServiceReference. You should change your endpoint configuration:
contract="ServiceReference1.UploadWebServiceSoap"
to
contract="DPCServiceReference.UploadWebServiceSoap"
You have 2 lines with this error.
If this won't help try deleting customBinding and endpoint with Soap12.

Related

Could not find endpoint element with name '' and contract '' in the ServiceModel client configuration section

I have tried days to solve this damn error. I am calling the same service in asp.net and it works fine, but when I call it in a sharepoint solution it does not work. This is the error that I receive.
Could not find endpoint element with name 'WeatherSoap' and contract 'WeatherService.WeatherSoap' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.
this is my app.config in the library:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WeatherSoap" 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>
<customBinding>
<binding name="WeatherSoap12">
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Soap12" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<httpTransport manualAddressing="false" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
useDefaultWebProxy="true" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://wsf.cdyne.com/WeatherWS/Weather.asmx"
binding="basicHttpBinding" bindingConfiguration="WeatherSoap"
contract="WeatherService.WeatherSoap" name="WeatherSoap" />
<endpoint address="http://wsf.cdyne.com/WeatherWS/Weather.asmx"
binding="customBinding" bindingConfiguration="WeatherSoap12"
contract="WeatherService.WeatherSoap" name="WeatherSoap12" />
</client>
</system.serviceModel>
This is my C# code
WeatherService.WeatherSoapClient client = new WeatherService.WeatherSoapClient("WeatherSoap");
WeatherService.WeatherReturn result = client.GetCityWeatherByZIP(txtZip.Text);
this is the code that I use in code behind in both sharepoint visual web part and in asp.net web page. The strange thing is that it works fine in asp.net but not in sharepoint.
I'm calling the service in a same project.
Look at this link: http://msdn.microsoft.com/en-us/library/ff647110.aspx
You may need to add configure the wcf endpoint programmatically for the sharepoint web part.

How do i call webservice from windows service

I have a windows service from which I am trying to call a method under remote webservice but I am getting error that "Could not find default endpoint element that references contract 'MyWebService.BookingCitySoap' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element."
Following is the code for that
.cs File
MyWebService.BookingCitySoapClient ws = new MyWebService.BookingCitySoapClient();
ws.CallBookStatus();
ws.CallCanStatus();
App.config
<bindings>
<basicHttpBinding>
<binding name="BookingCitySoap" 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://localhost:51317/Web/BookingCity.asmx"
binding="basicHttpBinding" bindingConfiguration="BookingCitySoap"
contract="MyWebService.BookingCitySoap" name="BookingCitySoap" />
</client>

Content type mismatch when consuming java wsdl from .net

There is a wsdl hosted on apache or jboss on a remote server that I am trying to use in my c# project. I have added a service reference in visual studio, which automatically generated an app.config file for me, where the system.serviceModel section looks as follows
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ArtesiaWebServicesHttpBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="655360" maxBufferPoolSize="524288" maxReceivedMessageSize="655360"
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://serverpath/ArtesiaWebServices"
binding="basicHttpBinding" bindingConfiguration="ArtesiaWebServicesHttpBinding"
contract="DAMService.ArtesiaWebServicesInterface" name="ArtesiaWebServicesHttpPort" />
</client>
</system.serviceModel>
At runtime, during a method call, I get the following error:
The content type multipart/related; type="application/xop+xml"; start=""; start-info="text/xml"; boundary="----=_Part_386_1206794365.1374255761229" of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly.
What could be the problem?
The problem was solved by changing messageEncoding property of the binding to "Mtom" instead of "Text"

Referenced name for my WCF service - Customers.svc or CustomersWcfDS.svc?

I have the following Visual Studio Web application structure:
CustomerManagement\
- Services
- Customers.aspx
- Customers.aspx.cs
- CustomersWcfDS.svc
- Default.aspx
- web.config
The following code is inside the <configuration> in the web.config file:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ICustomers" 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://localhost:1112/Services/Customers.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICustomers" contract="CustomersService.ICustomers" name="BasicHttpBinding_ICustomers" />
</client>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
I build the project and enter the following URL but there is no reactions.
http://localhost:1112/Services/Customers.svc
I also tried the following:
http://localhost:1112/Services/CustomersWcfDS.svc
and also
http://localhost:1110/Services/Customers.svc
and
http://localhost:1110/Services/CustomersWcfDS.svc
(The port 1110 was tested because of the Project Properties Port number was set to 1110.)
but it still fail to display something similar like the following illustration
So, is there any expert that can advise me where have my WCF service URL gone to?
Hi based on your image,
I think you have renamed the service name as Customers.svc . But still it refering to the previous one. What you can do is try to find the "SimpleService.svc" in your entire solution
and rename it as Customers.svc. If you have any problem put it as a comment.

Web Service Creating Instance Problem -> Could not find default endpoint element that references contract 'MyWebService.ClassName'

i want to use the below Web-Service :
https://acquirer.sb24.com/ref-payment/ws/ReferencePayment?WSDL
and builded config file after adding ->
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="PaymentIFBinding" 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="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="PaymentIFBinding1" 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="https://acquirer.sb24.com:443/ref-payment/ws/ReferencePayment"
binding="basicHttpBinding" bindingConfiguration="PaymentIFBinding"
contract="SB24Service.PaymentIF" name="PaymentIFPort" />
</client>
</system.serviceModel>
</configuration>
i want to call verifyTransaction method of this WebService :
PaymentIFClient pic = new PaymentIFClient();
double pic_result = pic.verifyTransaction(str1, str2);
but the first line throws the below error :
Could not find default endpoint element that references contract
'SB24Service.PaymentIF' in the ServiceModel client configuration
section. This might be because no configuration file was found for
your application, or because no endpoint element matching this
contract could be found in the client element.
EDIT :
"This error can arise if you are calling the service in a class
library and calling the class library from another project." -> My
Situation is like this ...
what should i change i configuration file ?
thanks in advance
Editing wcf configuration by hand is tricky, as there are many sections that need to be correct and correctly reference each other. Try opening your app.config file in SvcConfigEditor (also available from the Tools menu in Viusal Studio). It is way easier to get things correct when having GUI help on what to do.

Categories