c# - WCF / Service Reference without Configuration File -


I have my own generated app without my C # app Depending on the config file, issues are coming up.

The app.config file contains the following:

   & Lt; / Startup & gt; & Lt; System.serviceModel & gt; & Lt; Binding & gt; & Lt; BasicHttpBinding & gt; & Lt; Binding name = "basic HttpBinding_LanguageService" /> & Lt; / BasicHttpBinding & gt; & Lt; / Binding & gt; & Lt; Customers & gt; & Lt; endpoint address = "http://api.microsofttranslator.com/V2/soap.svc" binding = "basicHttpBinding" bindingConfiguration = "BasicHttpBinding_LanguageService" contract = "Soap.LanguageService" name = "BasicHttpBinding_LanguageService" / & gt; & Lt; / Customer & gt; & Lt; /system.serviceModel> & Lt; / Configuration & gt;  

In terms of this, I used the following method:

  internally stable Soap.LanguageServiceClient CreateWebServiceInstance () {binding = new BasicHttpBinding BasicHttpBinding (); Binding .name = "original HttpBinding_LanguageService"; Binding. Text encoding = systemtext Encoding.utf8; Return new SOAP. Language Service Client (Binding, New Endpoint Address ("http://api.microsofttranslator.com/V2/so.s.ccs")); }  

However, even if I get the exception of actions call CreateWebServiceInstance () before I execute Translate service, I do without this:

The reference contract that can not be found in the
  default endpoint element is' SOAP. Language Service 'in the Service Model Client Configuration section This may be because a configuration file was not found for your application, or because the endpoint element matching this agreement is not found in the client element. I'm not familiar with  BasicHttpBinding , so I'm not sure where the starting ... > 

Some questions first. As I read it, you are trying to consume a service. What this service revealed its Dbludisel now you are trying to consume it without using the proxy classes generated by, for example SVCUtil () / VisualStudioAddServiceReference? Or are you just trying to configure binding in the code instead of in your app.config?

If you are trying to consume the service without generating proxy classes, then specify the above so you need to work with dynamic dynamic proxy (output).

or if you have occurred proxy classes, you need to actually configure the compulsive use app.config, because it is much more reliable (for example when you are in production Then think about changing endpoint address.) If you do not really want to use the app.config binding, after the way you are doing this, now I suspect that you have to Have forgotten to add, which you want to use in your bondage.

View the ABC of services: ()

  address binding contract  

You are already the first two, I did not last Look at

Edit

After examining your problem in depth and also seeing that there is a public server, I can communicate with the service Was able to create a binding as well. (In addition to obtaining a non-authorized exception to me, which is normal because I do not have a token.

To join the service: Add a service reference for the service in Visual Studio.

remove the second app which will be generated from the top. >

  var binding = new BasicHttpBinding () ;. var client = new LanguageServiceClient (bondage, new EndpointAddress ( "http://api.microsofttranslator.com/V2/soap.svc"));  

Step 4: Use the client to call a method. If you are registered for the service, you will need to add an "AppID". At this point you should not face any problems.

Let me know if you will face them in some way.


Comments