Reputation: 642
I'm having issues setting up Microsoft Translator SOAP Service with my c# application without it relying on its generated app.config file.
The app.config file contains the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_LanguageService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://api.microsofttranslator.com/V2/soap.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_LanguageService"
contract="Soap.LanguageService" name="BasicHttpBinding_LanguageService" />
</client>
</system.serviceModel>
</configuration>
In reference to this Stack answer, I used the following method:
internal static Soap.LanguageServiceClient CreateWebServiceInstance()
{
BasicHttpBinding binding = new BasicHttpBinding();
binding.Name = "BasicHttpBinding_LanguageService";
binding.TextEncoding = System.Text.Encoding.UTF8;
return new Soap.LanguageServiceClient(binding, new EndpointAddress("http://api.microsofttranslator.com/V2/soap.svc"));
}
However, even though I call CreateWebServiceInstance()
before I execute the translator service, I get this unhandled exception:
Could not find default endpoint element that references contract 'Soap.LanguageService' 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.
I'm not familiar with BasicHttpBinding
, so I'm not sure where to start...
Upvotes: 2
Views: 3691
Reputation: 1510
A few questions first. As I read it you are trying to consume a service. This service exposed its WDSL. Now are you trying to consume it without using the proxy classes generated by SVCUtil(for example)/VisualStudioAddServiceReference? Or are you just trying to configure your binding in code, instead of in the app.config?
If you are trying to consume the the service without generating proxy classes as specified above then you need tu work with dynamic proxy generating. ().
Otherwise if you have the proxy classes generated, then you should actually use the app.config to configure the binding, because it's a lot more convient. (Think about the endpoint address changing when you go into production for example.) If you really don't want to use the app.config binding. Then in the way you are doing it now I suspect you forgot to add the contract you want to use to your binding.
See the ABC of services: ()
Address
Binding
Contract
You already have the first two, I don't see the last one.
EDIT
After looking into your problem more in depth. And also noticing this is a public server. I was able to create a binding as well as to communicate with the service. (Except I get a non authorized exception, which is normal as since I don't have a token.
To connect to the service: In visual studio add a service reference to the service.
Second remove the app.config file that will be generated by the above. Step three add the following code somewhere.
var binding = new BasicHttpBinding();
var client = new LanguageServiceClient(binding, new EndpointAddress("http://api.microsofttranslator.com/V2/soap.svc"));
Step 4: Use the client to call a method. In the method you will have to add the "AppId" that you received when you registered for the service. Normally from this point you shouldn't encounter any problems anymore.
Let me know if you would encounter them anyway.
Upvotes: 8
Reputation: 642
I was able to get it to work...I was calling the SOAP instance twice, thus overriding the object.
Upvotes: 1