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.
Related
I have a web.config file that has the following elements:
<client>
<endpoint address="url_1" />
<endpoint address="url_2" />
<endpoint address="url_3" />
</client>
Now, I want to change it depending on the environment that I am deploying to. I have created a release pipeline that deploys to my dev and prod environment on Azure, I am using XML Variable Substitution to change whatever variables I need such as connectionString in my prod environment.
I want to change the 3 endpoint elements contents in the web.config file in my PROD environment as well.
For instance, it shoud look like this in the respective environments:
DEV:
<client>
<endpoint address="url_1" />
<endpoint address="url_2" />
<endpoint address="url_3" />
</client>
PROD:
<client>
<endpoint address="url_4" />
<endpoint address="url_5" />
<endpoint address="url_6" />
</client>
I looked into XML File Transformation, and I don't want to add onto the file. I want to remove url_1, url_2, url_3 and replace them with url_4, url_5, url_6
Is there a way on the release pipeline to accomplish this task without breaking the variable substitutions that I have added in place?
According to your description, if you want to change the multiple XML element contents during running the pipeline, I recommend that you use the extension task Magic Chunks. This task can transform configuration files during the build process.
You can install Magic Chunks task to your organization, then add it to your pipeline. It tested your web.config with below example settings for magic chunk task:
Regarding the parameters Path and transformations: You need to specify your own configuration file path and required transformations.
Below is my test, you can refer to it:
After the pipeline runs successfully, we check the artifact file and find that the elements in the config file have changed.
You can use Replace tokens task to achieve this. Note that you will have to save these variable values in the pipeline/Variable group. For eg: Value of url1 will be url_1 scoped to Dev Stage.
XML file setup:
<client>
<endpoint address="#{url1}#" />
<endpoint address="#{url2}#" />
<endpoint address="#{url3}#" />
</client>
Result:
Dev:
<client>
<endpoint address="url_1" />
<endpoint address="url_2" />
<endpoint address="url_3" />
</client>
Prod:
<client>
<endpoint address="url_4" />
<endpoint address="url_5" />
<endpoint address="url_6" />
</client>
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.
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
I get this:
An error occurred while receiving the HTTP response to http://localhost:8732/Design_Time_Addresses/PersistencyService/Service1/. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
Why do I get this? I assume it is because the method takes about 1 min to complete. How can disable any time limit?
I get this when running in VS a Windows form project that uses a WCF service in the same solution
My WCF configuration:
edit:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="LongRunning" sendTimeout="00:10:00" />
</wsHttpBinding>
</bindings>
<client>
<endpoint name="Default"
address="http://localhost:8732/Design_Time_Addresses/PersistencyService/Service1/"
binding="wsHttpBinding"
bindingConfiguration="LongRunning"
contract="PersistencyService.IService1" />
</client>
<services>
<service name="PersistencyService.Service1">
<endpoint
address=""
binding="wsHttpBinding" bindingConfiguration=""
contract="PersistencyService.IService1" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/PersistencyService/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
The exception message is An existing connection was forcibly closed by the remote host.
I must also add that I get about 70MB of data from the service
On the client side, you need to add some settings to your app.config:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="LongRunning" sendTimeout="00:10:00" />
</wsHttpBinding>
</bindings>
<client>
<endpoint name="Default"
address="....."
binding="wsHttpBinding"
bindingConfiguration="LongRunning"
contract="IYourServiceContract" />
</client>
</system.serviceModel>
You didn't give us much to go on - no config, nothing.... so I'm left just guessing what settings you might have.
Basically, you need to define a binding configuration for the type of binding you're using, and you need to increase the sendTimeout attribute on that binding configuration (here in my sample: 10 minutes). You cannot completely turn off the timeout - you can increase it, but not turn it off.
Then, your client side config must make a reference to that binding configuration you've defined, by specifying a bindingConfiguration="...." attribute on the <endpoint> configuration, and using the same name for the binding configuration as when you defined it.
Maybe this is enough - but maybe, you'll also need to increase some of the timeouts on the server side. Try this first - if it doesn't work, come back and ask again - and please, next time: provide us with some more useful info, like your code and config!
I'm creating a WCF service which, at the moment, exposing a number of contracts using a basicHttpBinding. However, I now want to use the service locally on the same machine, and a netNamedPipeBinding seems more appropriate in terms of performance. For that reason, I want to expose the service using a named pipe and HTTP.
At the moment I'm doing this with the following configuration:
<service name="WCFService.MyService" behaviorConfiguration="serviceBehaviour">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/MyService" />
<add baseAddress="net.pipe://localhost/MyService" />
</baseAddresses>
</host>
<endpoint address="calculator" binding="basicHttpBinding" contract="WCFService.ICalculatorService" />
<endpoint address="database" binding="basicHttpBinding" contract="WCFService.IDatabaseService" />
</service>
This appears to work fine, but on closer inspection the endpoints are still using the basicHttpBinding. This works, but I get the impression it's creating unnecessary overhead.
Do I need to create an endpoint for each contract, and each binding type (i.e. basicHttpBinding and netNamedPipeBinding) or am I going about this completely wrong?
(If it's not clear, I'm fairly new to WCF!)
Yes, you need to specify multiple endpoints (1 endpoint per binding):
<endpoint address="calculator" binding="basicHttpBinding" contract="WCFService.ICalculatorService" />
<endpoint address="database" binding="basicHttpBinding" contract="WCFService.IDatabaseService" />
<endpoint address="calculator" binding="netNamedPipeBinding" contract="WCFService.ICalculatorService" />
<endpoint address="database" binding="netNamedPipeBinding" contract="WCFService.IDatabaseService" />