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.
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 have a class library, which calls into a Webservice. When i try and instantiate a new instance of the client, I am being thrown the following error is VS:
An exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll but was not handled in user code
Additional information: Could not find default endpoint element that references contract 'SanctionsCheckingService.ISanctionsCheckingService' 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.
My app.config file contains the following, which looks correct:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISanctionsCheckingService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:56200/SanctionsCheckingService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISanctionsCheckingService"
contract="SanctionsCheckingService.ISanctionsCheckingService"
name="BasicHttpBinding_ISanctionsCheckingService" />
</client>
</system.serviceModel>
Can anyone point to why this is happening?
I have a wcf config in client side. I need use a key in AppSettings by ServerIP Name for other sections in App.Config instead of localhost, Because count of my endpoints is many and my server ip is variable. How can I it?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ServerIP" value="localhost"/>
</appSettings>
<system.serviceModel>
<bindings>
...
</bindings>
<client>
<endpoint address="net.tcp://localhost:9000/WcfServices/Person/PersonService"
binding="netTcpBinding" bindingConfiguration="RCISPNetTcpBindingWpf"
contract="Common.ServiceContract.IPersonService" name="BasicHttpBinding_IPersonService">
<identity>
<dns value="localhost" /> <!--How use ServerIP in appSettings instead of localhost-->
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Normally you can not do that, but you might be able to use web.config transformations if you are using VisualStudio 2010. I think you have to use web deploy, or run an MSBuild task yourself to run the transforms.
you could not use appsettings in app.config itself.
you have two possibilities:
-use appsettings by code like making your our custom section
http://haacked.com/archive/2007/03/12/custom-configuration-sections-in-3-easy-steps.aspx
-use a nant build or msbuild with a placeholder
How to use MSbuild property in TransformXml task?
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.