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);
}
Related
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 facing problem while consuming the webservice and making an web service call.
I am creating the class library application which will generate the dll and this dll will be used by some other application to connect the webservice.I have received the WSDL file from third part and I "Add a service reference" and used all the proxy classes to create my soap body. Now I have two issues I need to add the wsse:security header to my soap message like below
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>username</wsse:Username>
<wsse:Password>password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
To handle this and to connect the webserivce endpoint address have modified my app.config file (which got generated when add service reference) to include this as header tag. below is my app.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ICMS-Http-WSBinding">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://devs-dp-in.wellpoint.com/Claims/2.0/Get_iHealthICMS_Results"
binding="basicHttpBinding" bindingConfiguration="ICMS-Http-WSBinding"
contract="Ihlth_Service1.ICMSHttpWSPortType" name="ICMS-Http-WSPortType">
<headers>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>username</wsse:Username>
<wsse:Password>password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</headers>
</endpoint >
</client>
</system.serviceModel>
</configuration>
When I tried to initialize my client as below I am facing the error as Could not find endpoint element with name 'ICMS-Http-WSPortType' and contract 'Ihlth_Service.ICMSHttpWSPortType' 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
Service.CMSHttpWSPortTypeClient Client = new Service.CMSHttpWSPortTypeClient("ICMS-Http-WSPortType");
I modified my code to create a binding and endpoint address inside the code and pass to the client then it worked fine but again faced issue at the security header missing as I provided the security information in app.config file
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
EndpointAddress address = new EndpointAddress("https://devs-dp-in.wellpoint.com/Claims/2.0/Get_iHealthICMS_Results");
is there any way that I can read the app.config file or my code refer that config file to get the information rather giving inside the code.
This entire code is working fine in the windows application by reading the app.config file but not in the class library application is there any reason behind that ?
Any one please give some idea
The app.config of a DLL is, at best, a reminder of what needs to be placed in the app.config of the EXE that consumes your DLL or the web.config of a website that consumes your DLL.
It's not actually used by default by the configuration system, and it's slightly unfortunate that some tooling (such as Add Service Reference) will create one in a class library project and give no warning about this.
Hope someone here can help me solve this !
I'm writing a custom plugin for Microsoft CRM, which on the creation or update of certain entities, carries out some tasks in the background on our Sharepoint instance, which can't be completed via CRM workflows as they don't have the functionality.
The problem is, that when creating the Service Reference, the defintion for the webservice, with the endpoint address, etc is stored in the DLL's .config file. When deploying the CRM Plugin, the .config file isn't available either when deploying it to disk, or to the database, and the plugin fails as soon as the I try to use the Webservice.
I've had a look at some documentation for BasicHttpBinding, but I'm not entirely sure how I would go about creating the Webservice programmatically, so that it is entirely contained within the DLL.
I'm not bothered about being able to amend the details without recompiling, as the code will be pretty much static anyway.
I've tried defining the Service Reference in the project, as "TestDws"
BasicHttpBinding SharepointWS = new BasicHttpBinding();
SharepointWS.Name = "SharepointWebservice";
EndpointAddress EndPoint = new EndpointAddress("http://hostname/_vti_bin/dws.asmx");
TestDws.DwsSoapClient temp = new TestDws.DwsSoapClient(SharepointWS, EndPoint);
However, the plugin just craps out at this point.
The original .config doesnt have much more in the way of configuration
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DwsSoap" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://hostname/_vti_bin/dws.asmx"
binding="basicHttpBinding" bindingConfiguration="DwsSoap"
contract="TempDws.DwsSoap" name="DwsSoap" />
</client>
</system.serviceModel>
</configuration>
I recreated the Service Reference from scratch, and used the same BasicHttpBinding method as above and it worked second time round... albeit now with a HTTP401 on the Sharepoint Webservice !
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.
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.