I created a proxy Library Class in the Service Solution referencing the Contract Assembly as well and copied the libraries (Contract,Proxy) to another solution folder. Then referenced the Proxy,Contract and System.ServiceModel libraries in another class library where i need to use the one method contained, as well as adding an App.Config inside the library.
The Service is hosted in a windows forms application. The client is a class library called from a windows forms application.I haven't created an App.Config inside the windows form project. In fact the Windows Form project loads a control in a library and the control loads the library where i need to use the service method. So i thought i should only reference the (Contract and proxy) in the latest assembly since i wont use it anywhere else.
But i keep getting this error:
Could not find default endpoint
element that references contract
'Sign.Contracts.ISignDocument' 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.
App.Config in libray calling the proxy:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<client>
<endpoint
address="http://localhost:8731/SignHere"
binding="basicHttpBinding"
contract="Sign.Contracts.ISignDocument" />
</client>
</services>
</system.serviceModel>
</configuration>
App.Config in service Host:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="Sign.Service.SignDocumentService">
<endpoint
address="http://localhost:8731/SignHere"
binding="basicHttpBinding"
contract="Sign.Contracts.ISignDocument" />
</service>
</services>
</system.serviceModel>
</configuration>
the Proxy class:
namespace Sign.Proxies
{
public class Proxy : ClientBase<ISignDocument>, ISignDocument
{
public string SignDocument(string document)
{
return Channel.SignDocument(document);
}
}
}
the Contract class:
namespace Sign.Contracts
{
[ServiceContract]
public interface ISignDocument
{
[OperationContract]
string SignDocument(string document);
}
}
Any ideas?
Any program has only a single configuration file. In your case, that's the app.config of the Winforms program, which gets copied to programName.exe.config when the program is built.
Any WCF configuration has to be in that file. The fact that your library has an app.config doesn't matter. You need to copy the relevant configuration entries from the library's app.config, and merge them with the app.config of the Winforms application.
doooh...there is no parent element for the client endpoint information in the client app.config.
Related
I have a webservice, created by a Java application. I want to call its services from a C++ project. I've been trying gsoap and other C++ code generators, but they're all out of date or unsupported.
So I decided to add an interface in C#, meaning that I will create a SOAP client in C# that will call each function of the webservice (in VS2015, you can only do that in Windows Form Application, dunno why ...).
Then I will export these functions by compiling the C# project as a DLL with the nuget UnmanagedExports of robert giesecke, dll which I will load in my end project in C++.
However, when I try to call the webservice in the C++ script, my app crashes with this log
Unhandled Execption: System.InvalidOperationException :
Could not find default endpoint element that references contract DockersWS.DockersWS
in the ServiceModel client configuration section. This might be because no configuration
file was found in your application or because no endpoint element matching this contract
could be found in the client element
at RawCSSoap\Services references\DockersWS\Reference.cs line 898
DockersWS is the name of the webservice called in the C# SOAP Client. The line 898 from References.cs looks like this :
public DockersWSClient() {}
I create the client in the C# app like this, directly in the function I'm exporting.
DockersWS.DockersWSClient client = new DockersWS.DockersWSClient();
My app.config generated by VS2015 when I added the Service Reference looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DockersWSPortBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://nxl35726:8080/DockersWS/DockersWS"
binding="basicHttpBinding" bindingConfiguration="DockersWSPortBinding"
contract="DockersWS.DockersWS" name="DockersWSPort" />
</client>
</system.serviceModel>
And the part of the WSDL file dealing with endpoint looks like this:
<binding name="DockersWSPortBinding" type="tns:DockersWS">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<!--bunch of operations-->
</binding>
<service name="DockersWS">
<port name="DockersWSPort" binding="tns:DockersWSPortBinding">
<soap:address location="http://nxl35726:8080/DockersWS/DockersWS" />
</port>
</service>
I've seen that sometimes a web.config file is generated also. But I didn't get it. Maybe that's the issue, but how can I generated it, then ?
I tried to add the app.config file to the C++ project as a Resource, but it didn't help.
So my question is : how can I fully use the SOAP client functions in the C++ project, without having this endpoint issue?
FOUND THE TRICK:
All this mess comes from the fact the app.config in the C# project is not exported in the DLL. So the C++ project has no way to configure its call to create a Client.
Therefore, the solution is to hard-code the client configuration in a C# function, export this function and call it in your C++ application.
Here is the code to replace the app.config file
BasicHttpBinding basicHttpbinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
basicHttpbinding.Name = "DockersWSPortBinding";
basicHttpbinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
basicHttpbinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
EndpointAddress endpointAddress = new EndpointAddress("http://nxl35726:8080/DockersWS/DockersWS?wsdl");
proxyClient = new DockersWS.DockersWSClient(basicHttpbinding, endpointAddress);
}
I am writing dll file for SAP B1, i need to embed App.Config in dll, no other option. Dll is using Web Service.
This is how my App.config looks like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WayBillsSoap">
<security mode="Transport" />
</binding>
<binding name="WayBillsSoap1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://services.rs.ge/WayBillService/WayBillService.asmx"
binding="basicHttpBinding" bindingConfiguration="WayBillsSoap"
contract="WayBillWS.WayBillsSoap" name="WayBillsSoap" />
</client>
</system.serviceModel>
</configuration>
You can't hard-code the App.config itself, because it simply isn't designed that way.
You can create your own config and embed it into your application using, for example, a resource file (.resx) or using constants to embed strings in a custom class.
But there is no way to embed the dll.
.NET does allow assemblies such as dlls to have their own yourdll.dll.config file. But you can't embed it. It must sit alongside you dll, just as it does for executables.
======= Edit after you posted your config =======
Ah. So here's the question. If you embed your config, that means by definition it can't change. So since you're okay with your config not changing -- since you want to embed it -- and it looks like you're using WCF, I would suggest you look at programmatically creating your WCF endpoint.
In WCF you can configure your endpoint in code instead of using an App.Config. That way you don't need a config at all.
Unfortunately, teaching your how to do this is beyond the scope of this question, but take a look at this answer: Programatically adding an endpoint. And try this google search: "wcf endpoint programmatically". That should help show you how to programmatically create a WCF endpoint.
I'm unsure about completely replacing the App.config but you can add and modify things found in it from code using the System.Configuration I've specifically used the System.Configuration.ConfigurationManager.AppSettings["SomeKey"]
Edit:
Doing that doesn't rewrite the App.config it simply temporarily adds/changes it
I am trying to use dependency injection with WCF REST (WebGet) and am having trouble understanding where I would use Unity to build my object to host the web service.
I have seen many examples all over the web, but they seem to all be hosting the service in a console app or Windows service.
Currently my config file looks like this:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="Services.MyRestService">
<endpoint address="http://localhost:8732/api" binding="webHttpBinding" contract="Shared.Services.IMyRestService"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
Currently the way it works is using the built in WCF service host in Visual Studio. However, I'd like to run this in IIS and use Unity to configure my container. Now I am using "bastard injection" to get the job done, but would like to use Unity to supply the data provider implementation, etc.
My question is, what configuration changes do I need to make to host this in IIS and also where do I configure the container and let IIS know about it.
There are no SVC files as this is a WCF Service Library.
Thanks in advance!
The "normal" way to do this would be to implement a custom IInstanceProvider WCF extension point, and add it through configuration. I've only done this with regular SOAP endpoints, but I think it would work the same for WebAPI.
Couple links that might help:
IInstanceProvider (MSDN)
Extending WCF Using IInstanceProvider
IInstanceProvider (MSDN Blog)
Integrating Unity with WCF
The 2nd link covers some of the XML configuration stuff for adding a custom IInstanceProvider to the behavior.
With WCF REST you would use WebServiceFactory and WebServiceHost as your base classes.
I'm creating a webservice client. And I have the problem - in MainWindow.xaml there is a message: 'Could not find endpoint element with name 'LightsWSSoap' and contract 'LightsWS.LightsWSSoap' 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 name could be found in the client element.'
In this file I have something like:
xmlns:vm="clr-namespace:LightsClient2.ViewModels"
<Window.DataContext>
<vm:MainWindowViewModel />
</Window.DataContext>
And in the MainWindowViewModel the constructor of webservice is used:
LightsWSSoap lService = new LightsWSSoapClient("LightsWSSoap");
Where 'LightsWS' is the name of the Service.
There is an app.config file and there are enpoints definitions in it:
<client>
<endpoint address="http://xxx/Lights/LightsWS.asmx"
binding="basicHttpBinding" bindingConfiguration="LightsWSSoap"
contract="LightsWS.LightsWSSoap" name="LightsWSSoap" />
<endpoint address="http://xxx/Lights/LightsWS.asmx"
binding="customBinding" bindingConfiguration="LightsWSSoap12"
contract="LightsWS.LightsWSSoap" name="LightsWSSoap12" />
</client>
What is wrong? Any ideas?
You will need to configure your client endpoint in the App.Config file in your WPF application.
If there is not already an App.Config file you can create one by adding a new item to your project and selecting "Application Configuration File".
The contents of App.Config should look something like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<endpoint binding="wsHttpBinding" contract="LightsWS.LightsWSSoap" name="LightsWSSoap" />
</client>
</system.serviceModel>
</configuration>
There is a lot more detailed information on MSDN - http://msdn.microsoft.com/en-us/library/ms731745%28VS.90%29.aspx.
You should add app.config file with definition of your endpoint. Usually it is create by Visual Studio. But if you created your ServiceReference in another assembly (for example, is separate dll), then just copy app.config from that assembly to your WpfApplication.
Try the ideas in this thread, especially the namespaces.
Any ideas how to fix this?
UserService.UserServiceClient userServiceClient = new UserServiceClient();
userServiceClient.GetUsersCompleted += new EventHandler<GetUsersCompletedEventArgs>(userServiceClient_GetUsersCompleted);
userServiceClient.GetUsersAsync(searchString);
.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_UserService"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:52185/UserService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_UserService"
contract="UserService.UserService"
name="BasicHttpBinding_UserService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="Shell.Silverlight.Web.Service3Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service behaviorConfiguration="Shell.Silverlight.Web.Service3Behavior"
name="Shell.Silverlight.Web.Service3">
<endpoint address=""
binding="basicHttpBinding"
contract="Shell.Silverlight.Web.Service3" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Could not find default endpoint element that references contract 'UserService.UserService' 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.
Resolved!
I didn't mention that this was a Silverlight application. I had the wcf reference in a DLL which had it's own "ServiceReferences.ClientConfig" file. I moved the contents of the DLL's ServiceReferences.ClientConfig to the main silverlight project and it worked.
I had a run in with the same problem. My application was also a Silverlight application and the service was being called from a class library with a custom UserControl that was being used in it.
The solution is simple. Copy the endpoint definitions from the config file (e.g. ServiceReferences.ClientConfig) of the class library to the config file of the silverlight application. I know you'd expect it to work without having to do this, but apparently someone in Redmond had a vacation that day.
You can also set these values programatically in the class library, this will avoid unnecessary movement of the config files across the library.
The example code for simple BasciHttpBinding is -
BasicHttpBinding basicHttpbinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
basicHttpbinding.Name = "BasicHttpBinding_YourName";
basicHttpbinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
basicHttpbinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
EndpointAddress endpointAddress = new EndpointAddress("http://<Your machine>/Service1/Service1.svc");
Service1Client proxyClient = new Service1Client(basicHttpbinding,endpointAddress);
Just in case anyone hits the same problem whilst using WPF (rather than WCF or Silverlight):
I had this error, when connecting to a Web Service. When my code was in the "main" WPF Application solution, no problem, it worked perfectly. But when I moved the code to the more sensible DAL-layer solution, it would throw the exception.
Could not find default endpoint element that references contract 'MyWebService.MyServiceSoap' 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.
As has been stated by "Sprite" in this thread, you need to manually copy the tag.
For WPF apps, this means copying the tag from the app.config in my DAL solution to the app.config in the main WPF Application solution.
I ran into the same issue, for whatever reason Visual Studio did not update the web config when I first added the service. I found that updating the Service Reference also fixed this issue.
Steps:
Navigate to the Service Reference Folder
Expand it
Right Click and Select update Service Reference
Observe web Config be updated
Change the web.config of WCF service as "endpoint address="" binding="basicHttpBinding"..." (previously binding="wsHttpBinding")After build the app, in "ServiceReferences.ClientConfig" ""configuration> has the value. Then it will work fine.
Rename the output.config produced by svcutil.exe to app.config.
it worked for me.
Do you have an Interface that your "UserService" class implements.
Your endpoints should specify an interface for the contract attribute:
contract="UserService.IUserService"
Not sure if this is an issue.
Endpoint and binding both have the same name
Not sure if it's really a problem, but I see you have the same name for your binding configuration ().
I usually try to call my endpoints something like "UserServiceBasicHttp" or something similar (the "Binding" really doesn't have anything to do here), and I try to call my binding configurations something with "....Configuration", e.g. "UserServiceDefaultBinding", to avoid any potential name clashes.
Marc
Had to add the service in the calling App.config file to have it work. Make sure that you but it after all . This seemed to work for me.
This problem occures when you use your service via other application.If application has config file just add your service config information to this file.
In my situation there wasn't any config file so I use this technique and it worked fine.Just store url address in application,read it and using BasicHttpBinding() method send it to service application as parameter.This is simple demonstration how I did it:
Configuration config = new Configuration(dataRowSet[0]["ServiceUrl"].ToString());
var remoteAddress = new System.ServiceModel.EndpointAddress(config.Url);
SimpleService.PayPointSoapClient client =
new SimpleService.PayPointSoapClient(new System.ServiceModel.BasicHttpBinding(),
remoteAddress);
SimpleService.AccountcredResponse response = client.AccountCred(request);
For those who work with AX 2012 AIF services and try to call there C# or VB project inside AX (x++) and suffer from such errors of "could not find default endpoint"... or "no contract found" ...
go back to your visual studio (c#) project and add these lines before defining your service client, then deploy the project and restart AX client and retry:
Note, the example is for NetTcp adapter, you could easily use any other adapter instead according to your need.
Uri Address = new Uri("net.tcp://your-server:Port>/DynamicsAx/Services/your-port-name");
NetTcpBinding Binding = new NetTcpBinding();
EndpointAddress EndPointAddr = new EndpointAddress(Address);
SalesOrderServiceClient Client = new SalesOrderServiceClient(Binding, EndPointAddr);
In case if you are using WPF application using PRISM framework then configuration should exist in your start up project (i.e. in the project where your bootstrapper resides.)
In short just remove it from the class library and put into a start up project.