Error connecting to asmx webservice on silverlight - c#

i'm trying to connect a silverlight 4 application with an asmx webservice, but i'm getting an "InvalidOperationException" when trying to do so.
The problem occurs on the first line of this function
private void AskWebService() {
WSCalledSoapClient client = new WSCalledSoapClient();
client.AskThisCompleted += new EventHandler<AskThisCompletedEventArgs>(client_AskThisCompleted);
client.AskThisAsync("the answer to life, universe and everything");
}
The error of the exception should translate something like this (haven't found the english version of it)
element 'message' not recognized on the service reference configuration. Note that only a subset of the Windows Communication Foundation configuration functionality is available in Silverlight.
Details of the webservice:
Is published outside the silverlight project
Files clientaccesspolicy.xml and crossdomain.xml are in place
Details of the Silverlight App
SL version is 4.0, .net framework is also 4.0
Given the same config and same treatment (i.e. steps to import the webservice, code used to call the webservice), the call to the webservice works without problem on a new silverlight application that contains only a button and a textblock
The app uses others webservices, but only one is giving problem.
Update:
Here is the ServiceReferences.ClientConfig
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WSCalledSoap" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://myip:someport/WSCalled.asmx"
binding="basicHttpBinding" bindingConfiguration="WSCalledSoap"
contract="SrvWSCalled.WSCalledSoap" name="WSCalledSoap" />
</client>
</system.serviceModel>
</configuration>
Any help will be appreciated.
Thanks.

Related

How to connect to WSDL service using Binding Url in .Net

I have been provided a Web Service which i need to consume in my MVC application .
The user has provided
WSDL URL :
http://abc.xyz.nirp.com:50000/dir/wsdl?p=ic/310c503c873138a884ddd3ee4a5738e6
Binding Url:
http://abc123.ad.xyx.com:50000/XISOAPAdapter/MessageServlet?senderParty=&senderService=BS_HARMONY_D&receiverParty=&receiverService=&interface=ABC_OS&interfaceNamespace=http%3A%2F%2Fabc.com%2Fhcm%2Fabc
I am able to add a service reference using the WSDL URL using SOAP credential but i also need to add these in the web configs and app configs which i am not able to understand where to put .
Pointers on how to use this Binding Url and put it in Web Config and App Config which be really helpful for me.
Check your web.config. After adding a service reference visual studio adds the endpoint in your web.config. You probably have a section like that:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="DefaultServiceEndpoint">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="ADDRESS_HERE"
binding="wsHttpBinding" bindingConfiguration="DefaultServiceEndpoint"
contract="ServiceReference1.SOME_CLASS" name="DefaultServiceEndpoint" />
</client>
</system.serviceModel>
You can change the address here.

Getting "No connection could be made because the target machine actively refused it" error while calling HTTPS SOAP service from C# Windows Service

There is external SOAP API which supports requests over HTTPS only.
I am having Windows Service written in C# and calling this web service.
Below is the configuration on Windows Service's config -
<system.serviceModel>
<client>
<endpoint address="https://myExtAPI.com/api_1234/service.asmx"
binding="basicHttpBinding" bindingConfiguration="myExtAPI"
contract="myExtAPI" name="myExtAPI" />
</client>
<bindings>
<basicHttpBinding>
<binding name="myExtAPI">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
When call is made to API method I am getting this error - "No connection could be made because the target machine actively refused it".
I have written another web application. With same configuration, I am able to make successful call to API method.
UPDATE: Windows Service is running under Network Service account.
What am I missing? Any suggestions?
Thanks in advance.

wcf service # iis - svc reachable but wsdl link not working

i wrote a wcf service and deployed it on a local iis without any problems.
local system:
windows 7 x64
iis 7.5
now i try to deploy my service on a remote system with iis server.
i copyed the service.svc, web.config and the bin directory to a folder of the other system.
after that i added a new application to the default website and linked it to the folder containing my files. i opend the browser an tryed to reach the svc file.
file is displayed correct with both wsdl links, but whene i click the links the url changes but the site dont change. tryed this on the remote system and on local client. same beavior on both systems.
remote system:
windows server 2012 r2 x64
iis 8.5
what ive done:
added a service behavior which enables service metadata
set the httpGetEnabled=True on that service metadata behavior to allow http browsing to that metadata
added mex endpoint on my service
here my web.config:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MetadateBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service
behaviorConfiguration="MetadateBehavior"
name="ServerLib.Handler.WcfReciveHandler">
<endpoint
address=""
binding="wsDualHttpBinding"
contract="Common.Contracts.IServerContract" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
i found a similar post here but with no answer to my problem. (WCF hosting: Can access svc file but cannot go to wsdl link).
i enabled tracing on my service but no logs are created so far. so i think the service is not running. on my local system togs are created.
i tryed to add a service reference to my client project with the url of the svc file, but this ends with an error:
There was an error downloading '\http://dev.develop.local/asd/Service.svc/_vti_bin/ListData.svc/$metadata' The request failed with HTTP status 404: Not Found. Metadata contains a reference that cannot be resolved:
followed by html document - think the file that is displayd whene i access the svc file.
ive checked my application eventlog on the remote system and noticed following error that seems to be written whene i tryed to add the service reference:
WebHost failed to process a request.
Sender Information: System.ServiceModel.Activation.HostedHttpRequestAsyncResult/24984138
Exception: System.Web.HttpException (0x80004005): There was no channel actively listening at 'https://dev.develop.local/asd/Service.svc/mex'. This is often caused by an incorrect address URI. Ensure that the address to which the message is sent matches an address on which a service is listening. ---> System.ServiceModel.EndpointNotFoundException: There was no channel actively listening at 'https://dev.develop.local/asd/Service.svc/mex'. This is often caused by an incorrect address URI. Ensure that the address to which the message is sent matches an address on which a service is listening.
at System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
i hope that someone can help.
You are missing the configuration section for the connection binding for "wsDualHttpBinding". You need to add a bindingConfiguration attribute to your endpoint element and point it to a binding configuration element.
It should look something like this (this is for wsHttpBinding not wsDualHttpBinding):
<bindings>
<wsHttpBinding>
<binding name="wsHttpBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="524288"
messageEncoding="Text" textEncoding="utf-8"
useDefaultWebProxy="true">
<reliableSession enabled="true" ordered="true"/>
<readerQuotas maxDepth="32" maxStringContentLength="52428800" maxArrayLength="52428800"
maxBytesPerRead="52428800" maxNameTableCharCount="52428800" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="None" algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
thanks toadflakz. i finally got it.
there have been several problems. your answer helps with one (point 2) of them.
the server and website i published the service only accepted https and my service dont provide the metadata via https. solution was to add httpsGetEnabled to my serviceMetadata.
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
that was the main problem of the wsdl file that was not loaded correctly. after adding this all went fine but communication failed - recived exceptions that point to a authentication problem - > thats point 2
wsDualHttpBinding requires as toadflakz said a bindingConfiguration. at least the information that no security mode is required. my binding config looks like this.
<wsDualHttpBinding>
<binding name="wsHttpDual">
<security mode="None">
<message clientCredentialType="None" algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
after that i added a new website for my service listening to http requests on a very high port. client seems to do something but recived a timeout. i added the port to incoming connections on server firewall but it was not enough - brings me to problem 3.
my communication was blocked by the client firewall. i added the server ip clientside - working fine now.
Restarting the visual studio solved my problem, I know its weird, but for someone who has tried everything and still failed , just try restarting visual studio. Hope it helps some one.

WCF 4.5 - multiple web services

I would like to consume 2 WCF web services located on 2 different hosts (the first accessible in HTTPS and the second one in HTTP). Both present the same methods, but the first one is on the production server, while the second one is on a test server.
When I add the references in my Visual Studio 2012 (express), I get 2 namespaces ; for now, the only way I found to consume these services is to use the interfaces and classes generated in these namespaces.
I would like to use only one web service, depending of a configuration item, indicating if I'm in debug or release mode.
How can I do that by code ?
Here is my config file :
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ILotWebContract">
<security mode="Transport" />
</binding>
<binding name="BasicHttpBinding_ILotWebContract1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://xxx/Services/WebService/LotWebService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ILotWebContract"
contract="eMol.ILotWebContract" name="BasicHttpBinding_ILotWebContract" />
<endpoint address="http://yyy/Services/WebService/LotWebService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ILotWebContract1"
contract="eMolTest.ILotWebContract" name="BasicHttpBinding_ILotWebContract1" />
</client>
</system.serviceModel>
I tried to change the endpoint's address :
eMolTest.LotWebContractClient client = new eMolTest.LotWebContractClient();
client.Endpoint.Address = new System.ServiceModel.EndpointAddress("https://xxx/Services/WebService/LotWebService.svc");
client.Endpoint.Binding = new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.Transport);
but the exception generated while running the client indicate that the links between client and service probably do not correspond.
I also tried to indicate the name of the endpoint when I call the proxy's contructor :
eMolTest.LotWebContractClient client = new eMolTest.LotWebContractClient("BasicHttpBinding_ILotWebContract");
but again it does not work because of the namespaces which are different (the contract's name contains the namespace's name, and can therefore not be found in the endpoint as defined in the config file).
So, if someone has a good idea ...
Thanks !
Chris
If you have two services with the exact same contract, you should share it's contract as a contract assembly between all three parties and use a ChannelFactory class to create the proxy yourself. That way you don't have two service references that although they represent the same contract are incompatible from a compiler perspective.

WCF: Cannot find endpoint reference

I am working on a SharePoint 2013 webpart and a label on the webpart needs to communicate with a SQL Server data table using WCF. I have created the WCF interface and main class, and have also invoked the service in my Visual webpart like this:
protected void Page_Load(object sender, EventArgs e)
{
WcfServiceReference1.Service1Client client = new WcfServiceReference1.Service1Client();
CustomerNameLbl.Text = client.GetCustomerName(ProjectIDDescLbl.Text);
}
Where WcfServiceReference1 is the added WCF service reference and a customer label text is being changed depending on the project number label. The project builds and deploys fine but when I add the webpart, I get this error: Could not find default endpoint element that references contract 'WcfServiceReference1.IService1' 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.
My app.config file is this:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://as-sv-dev02:2345/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="WcfServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
And web.config file (for SharePoint) is this:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://as-sv-dev02:2345/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="WcfServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
Can anyone guide me on how to resolve this? Am I going wrong somewhere?
After a lot of research, I found out that there was some problem with SharePoint which I don't really understand. Thankfully, in time, I chose not to go the SharePoint way and instead work with a simple .aspx page and that would resolve the issue. Just unhappy with Microsoft not offering as much support on such common issues.
I had the same problem and I found this link.
http://social.technet.microsoft.com/Forums/en-US/dea0763d-d6ea-4659-8ef0-8275514d066a/sp2010-consuming-web-service-in-visual-web-part?forum=sharepointdevelopmentprevious
I did it and worked fine. The problem is the deploy does not copy the service model configuration from the Visual Studio' app.config to the IIS's web.config.
I hope helps.
Best Regards.
Your client endpoint does not seem to have a default configuration (name="" or nameless). Try using:
WcfServiceReference1.Service1Client client = new WcfServiceReference1.Service1Client("BasicHttpBinding_IService1");

Categories

Resources