We have a setup, with a dev- test- and production environment. So when development and testing is done, each server has the same WebServices.
This is my first time doing so, but on the dev. environment I’ve written a WebService, and a C# client, using the Visual Studio (2017) ‘Add Service Reference’ feature. So I have an app.config file like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BizTalkInterfaceServiceSoapBinding">
<security mode="Transport">
<transport clientCredentialType="Basic" proxyCredentialType="Basic" realm="" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://xxx.xxx.xxx.xxx:xxxxx/and/so/on"
binding="basicHttpBinding" bindingConfiguration="BizTalkInterfaceServiceSoapBinding"
contract="ServiceReference.BizTalkInterface" name="BizTalkInterfacePort" />
</client>
</system.serviceModel>
</configuration>
And a Connected Services->ServiceReference structure, with a .wsdl, configuration.svcinfo, configuration91.svcinfo and Reference.svcmap files. I don’t know if there is any point in showing the contents of these files?
I initialize the client like this:
protected BizTalkInterfaceClient client;
protected ServiceBase()
{
client = new BizTalkInterfaceClient("BizTalkInterfacePort");
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
client.ClientCredentials.UserName.UserName = "xxx#xxxdomain";
client.ClientCredentials.UserName.Password = "xxxxxx";
}
Anyhow - This is all well and good, and works fine.
If you haven’t figured it out yet :-), I would like to define two other named endpoints, but I’m unsure on how to do it. Is there a wizard like way to do it, or do I have to copy/past the endpoint in the app.config and configuration files?
Any help would be greatly appreciated. Thanks a lot in advance.
You should be able to copy and paste this endpoint in your <client> node:
<endpoint address="https://xxx.xxx.xxx.xxx:xxxxx/and/so/on"
binding="basicHttpBinding" bindingConfiguration="BizTalkInterfaceServiceSoapBinding"
contract="ServiceReference.BizTalkInterface" name="BizTalkInterfacePort" />
and just give it a different name.
Also, when you initialize you client you would use the corresponding name here:
client = new BizTalkInterfaceClient("BizTalkInterfacePort");
example:
<endpoint address="https://xxx.xxx.xxx.xxx:xxxxx/and/so/on"
binding="basicHttpBinding" bindingConfiguration="BizTalkInterfaceServiceSoapBinding"
contract="ServiceReference.BizTalkInterface" name="BizTalkInterfacePortProd" />
client = new BizTalkInterfaceClient("BizTalkInterfacePortProd");
If your service has multiple service endpoint, it should be like
<service name="Service.CalculatorService" >
<endpoint address="http://localhost:3721/calculator" binding="basicHttpBinding" bindingConfiguration="ECMSBindingConfig" contract="ServiceInterface.ICalculatorService"></endpoint>
<endpoint address="http://localhost:4000/calculator" binding="wsHttpBinding" contract="ServiceInterface.ICalculatorService"></endpoint>
</service>
And then you could add reference to the service using wsdl address.
After adding reference, there should be two endpoint in your client with endpoint name, like
<endpoint address="http://localhost:3721/calculator" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ICalculatorService" contract="Calculator.ICalculatorService"
name="BasicHttpBinding_ICalculatorService" />
<endpoint address="http://localhost:4000/calculator" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_ICalculatorService" contract="Calculator.ICalculatorService"
name="WSHttpBinding_ICalculatorService">
Then in your client , you could initialize your client using the name of your configuration just as Popo has written.
Related
I am new to web service have a doubt regarding setting of <client> endpoint in the web.config of Accounts.svc.
Please check the picture attached where i have explained my architecture.
Server Setting in iis service name:https://prddb02:448/Accounts.svc and
external wsdl :https://company.****/*****?SOAP
(authenticated with username,password & proxy)
<client>
<endpoint address="https://company.****/*****?SOAP"
binding="basicHttpBinding" bindingConfiguration="CodeItSoap"
contract="Service.CodeItSoap" name="CodeItSoap" />
</client>
OR
<client>
<endpoint address="https://prddb02:448/Accounts.svc"
binding="basicHttpBinding" bindingConfiguration="CodeItSoap"
contract="Service.CodeItSoap" name="CodeItSoap" />
</client>
Which end point address to use.
Please help me getting this clear.
So here is my problem. I have a client that is utilized within a service, and when I test said service using the built-in test host in Visual studio, all of the service contracts are available. But, when I try to test one of the service contracts, Visual studio spits out the following error
Could not find default endpoint element that references contract 'TestServiceReference.ITestService' 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.
Now, I know the immediate and obvious answer is to check my config to make sure that my endpoint is correct, but that is the thing, it is correct. I checked both the web.config for the service implementing the client, and the app.config for the client. Both endpoints are correct(at least I think they are).
Here is the web.config endpoint:
<endpoint address="http://testServiceRepo/TestServices/TestService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITestService"
contract="TestServiceReference.ITestService"
name="BasicHttpBinding_ITestService" />
Here is the app.config endpoint:
<endpoint address="http://testServiceRepo/TestServices/TestService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITestService"
contract="TestServiceReference.ITestService"
name="BasicHttpBinding_ITestService" />
The endpoints are the exactly the same, and they both reference TestServiceReference.ITestService. So, I am at a loss here. What would you guys suggest?
Thanks for any help!
This error can arise if you are calling the service in a class library and calling the class library from another project. In this case you will need to include the WS configuration settings into the main projects app.config if its a winapp or web.config if its a web app. how you are testing it ? Did you tried to create client proxy/class using svcutil and then test these methods. it also generates require configuration in output,config file which you can use.
Try settings like this:
client config:
<basicHttpBinding>
<binding name="BasicHttpBinding_ITestService" />
</basicHttpBinding>
<client>
<endpoint
address="http://testServiceRepo/TestServices/TestService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ITestService"
contract="TestServiceReference.ITestService"
name="BasicHttpBinding_ITestService" />
</client>
server config:
<basicHttpBinding>
<binding name="BasicHttpBinding_ITestService" />
</basicHttpBinding>
<behaviors>
<serviceBehaviors>
<behavior name="testBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="testBehavior" name="TestServiceReference.TestService">
<endpoint
address=""
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ITestService"
contract="TestServiceReference.ITestService"
name="BasicHttpBinding_ITestService" />
</service>
</services>
EDIT
Note: Actually if you are using service reference (generated proxy) it is enough to fix the settings of service, delete the content of <system.serviceModel> tag in client, and add/update your service reference. It will fix up your settings in the client's config file.
For me this exact issue happened when I accidentally 'fixed' the WCF endpoint as
<client>
<endpoint
address="http://testServiceRepo/TestServices/Testservice.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ITestService"
contract="TestServiceReference.ITestService"
name="BasicHttpBinding_ITestService" />
</client>
instead of
<client>
<endpoint
address="http://testServiceRepo/TestServices/TestService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ITestService"
contract="TestServiceReference.ITestService"
name="BasicHttpBinding_ITestService" />
</client>
(notice the lowercase 's' in the word TestService first address example)
This was for a c# project
This project working perfectly at my local pc but when I run at server I am getting this error.
The endpoint at 'http://Foo' does not have a Binding with the None
MessageVersion. 'System.ServiceModel.Description.WebHttpBehavior' is
only intended for use with WebHttpBinding or similar bindings.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BIServicesSoap" maxBufferPoolSize="20000000" maxBufferSize="20000000"
maxReceivedMessageSize="20000000" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://FooA"
binding="basicHttpBinding" bindingConfiguration="BIServicesSoap"
contract="FinansService.BIServicesSoap" name="BIServicesSoap" />
<endpoint address="http://FooB"
binding="basicHttpBinding" bindingConfiguration="BIServicesSoap"
contract="FinansNet.BIServicesSoap" name="BIServicesSoap1" />
</client>
</system.serviceModel>
Note: At server there is another WCF project runs and my project runs under a sub folder. could web configs mix?
I developed a C# console application that consumes a WCF service. All works fine on the local machine. When I created the set up files and distributed the exe and exe.config files, the application errors out on other machines on the same network with the below error:
The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state..
The WCF service endpoint URL - http://inblrlwssc251.wdf.corp:7980/AfariaService/Server is accessible form other machines as well. Unsure what can be going wrong.
The configuration for the service looks as below, I use the WSHTTP binding:
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true"
logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<bindings>
<netNamedPipeBinding>
<binding name="NetNamedPipeBinding_IServerService" />
</netNamedPipeBinding>
<netTcpBinding>
<binding name="NetTcpBinding_IServerService">
<security mode="Message" />
</binding>
</netTcpBinding>
<wsHttpBinding>
<binding name="WSHttpBinding_IServerService" />
</wsHttpBinding>
</bindings>
<!--
Modify the "adress" in each of the endpoint tags based on where the Afaria API service is hosted
-->
<client>
<endpoint address="http://inblrlwssc251:7980/AfariaService/Server"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IServerService"
contract="AfariaServerService.IServerService" name="WSHttpBinding_IServerService">
</endpoint>
<endpoint address="net.tcp://inblrlwssc251:7982/AfariaService/Server"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IServerService"
contract="AfariaServerService.IServerService" name="NetTcpBinding_IServerService">
</endpoint>
<endpoint address="net.pipe://localhost/AfariaService/Server"
binding="netNamedPipeBinding" bindingConfiguration="NetNamedPipeBinding_IServerService"
contract="AfariaServerService.IServerService" name="NetNamedPipeBinding_IServerService">
</endpoint>
</client>
</system.serviceModel>
Any help or a pointer in the right direction will be very much appreciated.
I know that this is old and you said it is resolved, but for posterity's sake this is not typically the result of passing incorrect credentials. Normally this is a result of the response from the server responding with more data that you've configured to accept in your buffers, exceeding the maxitemsinobject graph, or the response from the server taking too long, which causes an exception, which is handled... and this exception is the result of the next call (as fejesjoco and Tim pointed out).
When this occurs, it is best to reinitialize the client/serviceclient object (for this api, also call initContext) and then try the call again.
How to Send Large File From Client To Server Using WCF in C#? Below the configuration code.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="HttpStreaming_IStreamingSample"
maxReceivedMessageSize="67108864"
transferMode="Streamed">
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint
address="http://localhost:4127/StreamingSample.svc"
binding="basicHttpBinding"
bindingConfiguration="HttpStreaming_IStreamingSample"
contract="StreamingSample.IStreamingSample"
name="HttpStreaming_IStreamingSample" />
</client>
</system.serviceModel>
You need to check out streaming, as Dzmitry already pointed out.
In order to be able to send large files as a stream to your service, you'll need to:
create a service method that accepts a Stream as its input parameter
create a binding configuration (on both the server and the client) which uses transferMode=StreamedRequest
create a stream in your client and send it to the service method
So first off, you need a method in your service contract:
[ServiceContract]
interface IYourFileService
{
[OperationContract]
void UploadFile(Stream file)
}
Then you need a binding configuration:
<bindings>
<basicHttpBinding>
<binding name="FileUploadConfig"
transferMode="StreamedRequest" />
</basicHttpBinding>
</bindings>
and a service endpoint on your service using that binding configuration:
<services>
<service name="FileUploadService">
<endpoint name="UploadEndpoint"
address="......."
binding="basicHttpBinding"
bindingConfiguration="FileUploadConfig"
contract="IYourFileService" />
</service>
</services>
and then, in your client, you need to open e.g. a filestream and send that to the service method without closing it.
Hope that helps!
Marc
You can take a look at WCF Streaming feature.
In addition to increasing readerQuota settings (mentioned above) I had to also up the maxRequestLength inside the httpRuntime attribute.
<system.web>
<httpRuntime maxRequestLength="2097151" />
</system.web>