I had created an MVC application that had no authentication so I was advised to create a mvc project that has the 'Individual User Accounts' option selected which brings with it some controllers, models and views.
What I had done to keep my old class library data was rename the current class library as Projectold in my file explorer and created a new class library in Visual Studio with the same name(Project) then imported all the controllers, views, config files that I had from my previous library and included them in the new class library.
I have a proxy to 2 web services that exposes data for me to use. Because I only needed a new class library, I had the existing <system.serviceModel> tag already there in the existing service folder so I just copied and pasted it within the new web.config file in the new class library.
What has happened is that now I cannot access the web service to access the data. I am thrown the error:
System.InvalidOperationException
HResult=0x80131509
Message=Could not find endpoint element with name 'WebServiceSoap' and contract
'ProxyToWebService.WebServiceSoap' 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.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
My web.config file is (The proxy URL's have been anonymised):
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WebServiceSoap"/>
<binding name="SWebServiceSoap"/>
</basicHttpBinding>
<customBinding>
<binding name="WebServiceSoap12">
<textMessageEncoding messageVersion="Soap12"/>
<httpTransport/>
</binding>
<binding name="SWebServiceSoap12">
<textMessageEncoding messageVersion="Soap12"/>
<httpTransport/>
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://URL/URL/URL.asmx" binding="basicHttpBinding" bindingConfiguration="WebServiceSoap" contract="ProxyToWebService.WebServiceSoap" name="WebServiceSoap" />
<endpoint address="http://URL/URL/URL.asmx" binding="customBinding" bindingConfiguration="WebServiceSoap12" contract="ProxyToWebService.WebServiceSoap" name="WebServiceSoap12" />
<endpoint address="http://URL/URL/URL.asmx" binding="basicHttpBinding" bindingConfiguration="SWebServiceSoap" contract="ProxyToSWebService.SWebServiceSoap" name="SWebServiceSoap" />
<endpoint address="http://URL/URL/URL.asmx" binding="customBinding" bindingConfiguration="SWebServiceSoap12" contract="ProxyToSWebService.SWebServiceSoap" name="SWebServiceSoap12" />
</client>
</system.serviceModel>
I have returned to a back up copy and it works before I replace my old new class library with my new class library so the endpoint connections should be okay. Just when they are used in the new class library is where it breaks.
I cannot just copy the old web.config file either as because the Individual User Accounts option is selected, it has modified the web.config file.
My code for the proxy connection:
public InboundService()
{
proxy = new WebServiceSoapClient("WebServiceSoap", "http://URL/URL/URL.asmx");
Sproxy = new SWebServiceSoapClient("SWebServiceSoap", "http://URL/URL/URL.asmx");
}
Related
We have a Windows Form, C#, .NET 4.5.1 application that calls a class library also in C# and 4.5.1. It's worked for years without a problem. This week when I tried to make a change I've run in to a strange error and a strange work around. I'd love to know what is going on if someone could explain it.
So the error I'm getting is on the main form. The error is "Could not find default endpoint element that references contract 'ShipService.IShipService' in the ServiceModel client confirmation section. This might be because no configuration file was found in your application, or because no endpoint element matching hihs contract could be found in the client element."
I've found multiple links (see here, here, and here) that say to make sure the config in your class library matches what's in your main program. I tried this and was still getting the error. I didn't find any other suggestions besides "check your config".
Here's where it gets odd. If I delete my local copy and download the code from the master branch, I'm able to run the program with no errors as long as I don't open MainForm.cs. So, I debugged it and found the error was in the business logic layer in this method:
public void ResetShipService()
{
shipClient = new ShipServiceClient();
}
If I comment out the above, and instead create a new instance of ShipServiceClient instead of calling ResetShipService, everything works fine. The program runs and I can open MainForm.cs. I'm just moving it a different place in the same class. I have no idea why this works or what is going on here. Can someone explain what's going on and/or give me a better way of fixing this than just commenting out code and moving it somewhere else?
Here's the layout of what's involved:
ShippingService - class library
- Endpoint is net.tcp://localhost:9000/Shipping
- I have no access to change this class library
ShippingApplication - Windows Form Application
- Shipping - Main project
- MainForm.cs - This is the form that shows the design time error
- User controls
- ItemsControl.cs - This is a user control in MainForm.cs that calls the business logic layer
- ShippingBusinessLogicLayer - Business logic layer
- ShippingBLL.cs - Calls the ShippingService class library
Here's the error I'm getting:
Here's the code in the BLL where the error is coming from:
public class ShipmentBLL
{
private ShipServiceClient shipClient;
public ShipmentBLL()
{
ResetShipService();
}
public void ResetShipService()
{
shipClient = new ShipServiceClient(); // If I comment out this, the design time error goes away
}
private ShipmentDTO processShipment (QuickShipmentDTO QuickShipmentDTO, bool TestShipment = false, bool RelieveInventory = true)
{
Ship ship = new Ship();
if (shipClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)
{
ResetShipService();
}
ship = shipClient.ProcessShipment(ship, TestShipment);
}
}
Here's the code in ItemsControl.cs that creates the instance of the BLL:
public partial class ItemsToShipControl : UserControl
{
public ItemsToShipControl()
{
InitializeComponent();
shipmentBLL = new ShipmentBLL();
}
}
Here's code from MainForm.cs designer setting up the user control:
this.ItemsToShipPane = new NTSupply.NTShipping.UserControls.ItemsControl();
this.Controls.Add(this.ItemsToShipPane);
private UserControls.ItemsControl ItemsToShipPane;
Here's service model section of the app.config from the ShippingService:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="longTimeoutBinding" receiveTimeout="00:30:00" sendTimeout="00:30:00">
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="ShippingServiceBehavior" name="NTSupply.Shipping.ShipService">
<endpoint address="net.tcp://localhost:9000/Shipping" binding="netTcpBinding" bindingConfiguration="longTimeoutBinding"
contract="NTSupply.Shipping.IShipService" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9000/Shipping" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ShippingServiceBehavior">
<serviceMetadata/>
<serviceDebug includeExceptionDetailInFaults="True" />
<dataContractSerializer maxItemsInObjectGraph="65536" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Here's the app.config from the Shipping project:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IShipService" sendTimeout="00:30:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"/>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://192.168.1.12:9000/Shipping" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IShipService" contract="ShipService.IShipService" name="NetTcpBinding_IShipService">
</endpoint>
</client>
</system.serviceModel>
Here's the app.config from the BLL:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IShipService" />
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:9000/Shipping" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IShipService" contract="ShipService.IShipService"
name="NetTcpBinding_IShipService">
<identity>
<servicePrincipalName value="host/NTSUPSHIP.anthonymulinaro.local" />
</identity>
</endpoint>
</client>
</system.serviceModel>
By default, when we invoke the service by adding service reference in the class library project, there might be something amiss during cooperating with the main project. The service proxy only uses the main project configuration (Appconfig) instead of the previous configuration that is auto-generated in the class library project. In order to make it work properly, we have to move the ServiceModel section in the class library project into the configuration file recognized by the hosting environment, namely the main project configuration file.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/deploying-a-wcf-library-project
In your actual scenario, the process of instance a client proxy will try to find the client endpoint, related binding property, etc. This might come to a trouble. We could use the name of the endpoint to instance the client proxy, provided that the configuration is recognized by the main project.
NetTcpBinding_IShipService
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client("NetTcpBinding_IShipService");
Feel free to let me know if there is anything I can help with.
I have created the wcf service. I added the service using "add service refence" in vs2017.
after adding the service i am trying to access using below function (c#)
List<ProductData> data = new List<ProductData>();
ServiceReferenceIHS.PriceClient ns = new ServiceReferenceIHS.PriceClient();
data = ns.GetPricesData(clientName, password, lstISHCode.ToArray(), Startdate, EndDate).ToList();
I am providing the values to GetPricesData method.
below is the exception message.
There was no endpoint listening at http://localhost:8080/Test.svc that could accept the message.
This is often caused by an incorrect address or SOAP action.
See InnerException, if present, for more details.
The inner exception is Unable to connect to the remote server
this is the appconfig configuration.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IPrice" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/Test.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPrice"
contract="ServiceReferenceIHS.IPrice" name="BasicHttpBinding_IPrice" />
</client>
</system.serviceModel>
what is wrong in my code.
How do I run a SSRS report using VS2015 in a SSIS package. The following answer is not the latest way of doing this apparently from what I have read. This post is the old way
how to run SSRS reports using SSIS? because it mentions ReportExecutionService not ReportExecutionServiceSoapClient.
I also tried another sites answer when I call the proxy (like first line of code it fails.
var webServiceProxy = new ReportExecutionServiceSoapClient("ReportExecutionServiceSoap")
Error I get is:
An exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll but was not handled in user code
Additional information: Could not find endpoint element with name 'ReportExecutionServiceSoap' and contract 'ServiceReference1.ReportExecutionServiceSoap' 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.
It does not matter if I use the default config or the one from the below example or if I call the constructor that does not require a endpoint, so I am lost what else to try.
Refer to:
C# Example in SSIS
app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services />
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingConfig" allowCookies="true" maxReceivedMessageSize="5242880">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://<myserver>/reportserver/ReportExecution2005.asmx?WSDL"
binding="basicHttpBinding" bindingConfiguration="basicHttpBindingConfig"
contract="ServiceReference1.ReportExecutionServiceSoap" name="ReportExecutionServiceSoap" />
</client>
</system.serviceModel>
</configuration>
Also at design time there is a warning:
The 'contract' attribute is invalid - The value 'ServiceReference1.ReportExecutionServiceSoap' is invalid according to its datatype 'clientContractType' - The Enumeration constraint failed.
This question already has answers here:
Read WCF service endpoint address by name from web.config
(3 answers)
Closed 1 year ago.
I have asp.net web application and have the following in my app.config file.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Test" />
<binding name="Test1">
<security mode="Test" />
</binding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://test:90001"
binding="basicHttpBinding" bindingConfiguration="Test"
contract="Test" name="HTTP_Port" />
</client>
</system.serviceModel>
How i can get/read endpoint address value?
I have come accross the this solution but it is not working for me asking for exe file path. Not sure which exe path file?
var serviceModel = ServiceModelSectionGroup.GetSectionGroup(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));
var endpoints = serviceModel.Client.Endpoints;
foreach (ChannelEndpointElement e in endpoints)
{
if (e.Name == "HTTP_Port")
Console.WriteLine(e.Address);
}
Console.ReadLine();
To read endpoints from appconfig you need to add reference of System.ServiceModel.Configuration and use GetSectionGroup method which return the serviceModel group and you can access all the endpoints in that section,if you just need the one you can access specific with the endpoint name.
Also in the appconfig you provided the port is invalid, I got and error while reading the url with that port I assume you just added that as an example.
I have several web services that I am connecting to from a Visual Studio C# project using service references. Two of the service references were created and work without a problem, and one of them took quite a lot of effort to get imported, and now seems to not be working.
I believe the problem lies in the app.config file since it is getting a "Could not find endpoint element" error when I try to create the client.
Here is the app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="RateQuoteSoap">
<security mode="Transport" />
</binding>
<binding name="RateQuoteSoap1" />
<binding name="QuoteSoap" />
<binding name="WebservicePrimusSoapBinding" />
</basicHttpBinding>
<customBinding>
<binding name="QuoteSoap12">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint
address="https://webservices.rrts.com/rating/ratequote.asmx"
binding="basicHttpBinding"
bindingConfiguration="RateQuoteSoap"
contract="RoadRunnerService.RateQuoteSoap"
name="RateQuoteSoap" />
<endpoint
address="http://services.echo.com/Quote.asmx"
binding="basicHttpBinding"
bindingConfiguration="QuoteSoap"
contract="EchoService.QuoteSoap"
name="QuoteSoap" />
<endpoint
address="http://services.echo.com/Quote.asmx"
binding="customBinding"
bindingConfiguration="QuoteSoap12"
contract="EchoService.QuoteSoap"
name="QuoteSoap12" />
<endpoint
address="http://api.shipprimus.com/"
binding="basicHttpBinding"
bindingConfiguration="WebservicePrimusSoapBinding"
contract="PrimusService.WebservicePrimusServicePort"
name="WebservicePrimusServicePort" />
</client>
</system.serviceModel>
</configuration>
The PrimusService is the one that is not working correctly, and the full error when I try to initialize the client like WebservicePrimusServicePortClient serviceClient = new WebservicePrimusServicePortClient("WebservicePrimusServicePort"); is
System.InvalidOperationException: Could not find endpoint element with name 'WebservicePrimusServicePort' and contract 'PrimusService.WebservicePrimusServicePort'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.
I have also tried to simply initialize a BasicHttpBinding object using the binding name and the endpoint name with no luck (short variable names for readability)
BasicHttpBinding a = new BasicHttpBinding("QuoteSoap"); // Works fine
BasicHttpBinding b = new BasicHttpBinding("WebservicePrimusSoapBinding"); // Fails
BasicHttpBinding c = new BasicHttpBinding("WebservicePrimusServicePort"); // Fails
It throws no error for binding a, but binding b and c fail with the error:
System.Collections.Generic.KeyNotFoundException: No elements matching the key 'WebservicePrimusSoapBinding' were found in the configuration element collection.
While not a direct solution, I ended up just taking the information from the app.config and creating my own BasicHttpBinding and EndpointAddress objects in code. This is more of a workaround than a fix for the problem, and I still don't know why I couldn't access the information in the app.config directly.
I followed the solution in this answer about how to consume a service without using the app.config file.
I created my BasicHttpBinding like
BasicHttpBinding binding = new BasicHttpBinding();
binding.Name = "PrimusServiceBinding"; // Completely Unnecessary
and my endpoint like
EndpointAddress endpoint = new EndpointAddress("http://api.shipprimus.com/");
and could connect to the service and retrieve information without a problem, even providing as little information as I did (basically just the address).