I'm doing a service to comunicate only for test and learning,
but I'm trying to change the URL Endpoint and its returning a error
n: There was no endpoint listening at http://servername:8732/TestService/ that could accept the message. This is often caused by an incorrect address or SOAP action.
That is my code:
private void button1_Click(object sender, EventArgs e)
{
var myBinding = new BasicHttpBinding();
myBinding.Security.Mode = BasicHttpSecurityMode.None;
var myEndPointAdress = new EndpointAddress("http://servername:8732/TestService/");
MyCalculatorServiceClient service = new MyCalculatorServiceClient(myBinding, myEndPointAdress);
MessageBox.Show(Convert.ToString(service.soma(Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox2.Text))));
}
App.config "Edited":
<?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="BasicHttpBinding_IMyCalculatorService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://servername:8732/TestService/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyCalculatorService"
contract="ServiceReference1.IMyCalculatorService" name="BasicHttpBinding_IMyCalculatorService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Related
I'm trying to consume a WebService in a console application, but I keep getting this error.
'Unable to load endpoint configuration section for
'Giftcard.WebServiceSoap' contract. Found more than one configuration
for the contract. Indicate the preferred endpoint configuration
section by name.'
This is my code:
public class Program
{
static void Main(string[] args)
{
UserWebService.WebServiceSoapClient webServiceSoapClient = new UserWebService.WebServiceSoapClient();
string id = "12345543";
webServiceSoapClient.Login(id);
}
}
WEB Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WebServiceSoap">
<security mode="Transport" />
</binding>
<binding name="WebServiceSoap1" />
</basicHttpBinding>
<customBinding>
<binding name="WebServiceSoap12">
<textMessageEncoding messageVersion="Soap12" />
<httpsTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="https://localhost:444/WebService.asmx" binding="basicHttpBinding"
bindingConfiguration="WebServiceSoap" contract="UserWebService.WebServiceSoap"
name="WebServiceSoap" />
<endpoint address="https://localhost:444/WebService.asmx" binding="customBinding"
bindingConfiguration="WebServiceSoap12" contract="UserWebService.WebServiceSoap"
name="WebServiceSoap12" />
</client>
</system.serviceModel>
</configuration>
I've added the reference to the webservice from here:
Add the bindingConfiguration="WebServiceSoap" name you want to use in the constructor of UserWebService.WebServiceSoapClient("WebServiceSoap").
public class Program
{
static void Main(string[] args)
{
UserWebService.WebServiceSoapClient webServiceSoapClient = new UserWebService.WebServiceSoapClient("WebServiceSoap");
string id = "12345543";
webServiceSoapClient.Login(id);
}
}
I have self hosting WCF service that contains it's own app.Config to expose endpoints required for the service contracts. If the service is started in the programs.cs main method it all works just fine and the metadata is exposed via the browser. However, I created a HostService class based on the ServiceBase class which in the same host library and is instantiated within the program.cs file. The HostService class starts the service and has a timer method to ping other client web services for information.
My question is, when I created the HostService : ServiceBase class and instantiate it from the main(), I have to put a duplicate app.Config file in the Service Library in order for the endpoints to properly exposed and return the metadata/wsdl. I don't want to maintain 2 duplicate app.config files if possible. Currently the host library and service library both require one. Is there a way to only have just one w/ the host that could be used for both? Sorry for the dumb question, but I'm new to WCF =)
Program.cs
static void Main(string[] args){
var service = new HostService();
service.StartHostService(args);
}
HostService.cs
public partial class HostService : ServiceBase
{
internal void StartHostService(string[] args)
{
this.OnStart(args);
Console.ReadLine();
this.OnStop();
}
....
}
Short answer is no. There must be two configs, one for the client that consumes the WCF and one for the server that exposes that communication methods with the WCF.
In order for your client to work, your config must be set with Client Configuration
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<client>
<endpoint
name="endpoint1"
address="http://localhost/ServiceModelSamples/service.svc"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IHello"
behaviorConfiguration="IHello_Behavior"
contract="IHello" >
<metadata>
<wsdlImporters>
<extension
type="Microsoft.ServiceModel.Samples.WsdlDocumentationImporter, WsdlDocumentation"/>
</wsdlImporters>
</metadata>
<identity>
<servicePrincipalName value="host/localhost" />
</identity>
</endpoint>
// Add another endpoint by adding another <endpoint> element.
<endpoint
name="endpoint2">
//Configure another endpoint here.
</endpoint>
</client>
//The bindings section references by the bindingConfiguration endpoint attribute.
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IHello"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard">
<readerQuotas maxDepth="32"/>
<reliableSession ordered="true"
enabled="false" />
<security mode="Message">
//Security settings go here.
</security>
</binding>
<binding name="Another Binding"
//Configure this binding here.
</binding>
</wsHttpBinding>
</bindings>
//The behavior section references by the behaviorConfiguration endpoint attribute.
<behaviors>
<endpointBehaviors>
<behavior name=" IHello_Behavior ">
<clientVia />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
notice the <client> tag specifying how the client must call the WCF.
and with Server Config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="myBindingConfiguration1" closeTimeout="00:01:00" />
<binding name="myBindingConfiguration2" closeTimeout="00:02:00" />
<binding closeTimeout="00:03:00" /> <!—- Default binding for basicHttpBinding -->
</basicHttpBinding>
</bindings>
<services>
<service name="MyNamespace.myServiceType">
<endpoint
address="myAddress" binding="basicHttpBinding"
bindingConfiguration="myBindingConfiguration1"
contract="MyContract" />
<endpoint
address="myAddress2" binding="basicHttpBinding"
bindingConfiguration="myBindingConfiguration2"
contract="MyContract" />
<endpoint
address="myAddress3" binding="basicHttpBinding"
contract="MyContract" />
</service>
</services>
</system.serviceModel>
</configuration>
Notice there is no <client> tag here.
I'm using this example and although the transfering method is streamed once I hit upload the ram consumption on the client jumps to 1GB. After the transfer is finished the memory isn't reduced. My code is below:
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
if (result == DialogResult.OK) // Test result.
{
if (File.Exists(openFileDialog1.FileName))
{
//System.IO.FileInfo fileInfo = new System.IO.FileInfo(openFileDialog1.FileName);
FileTransferServiceReference.ITransferService clientUpload = new FileTransferServiceReference.TransferServiceClient();
FileTransferServiceReference.RemoteFileInfo uploadRequestInfo = new RemoteFileInfo();
uploadRequestInfo.FileName = openFileDialog1.FileName;
uploadRequestInfo.Length = new FileInfo(openFileDialog1.FileName).Length;
uploadRequestInfo.FileByteStream = File.OpenRead(openFileDialog1.FileName);
clientUpload.UploadFile(uploadRequestInfo);
}
}
on the App.config there is
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.web>
<httpRuntime maxRequestLength="2097150"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ITransferService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://62.1.193.176/transferTEST/wcfTest.TransferService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITransferService"
contract="FileTransferServiceReference.ITransferService" name="BasicHttpBinding_ITransferService" />
</client>
</system.serviceModel>
</configuration>
I want to set the maxReceivedMessageSize in the App.config of the WCF Client.
If the maxReceivedMessageSize equals or is smaller then 4215 it works fine. Though when setting it to 4216 or any value above it, the default value of 65536 is taken.
My Client Code
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IConexaApiServic" maxReceivedMessageSize="4216" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://svsr02.conexa.local/HelloService/ConexaApiService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IConexaApiServic"
contract="ConexaApiService.IConexaApiService" name="BasicHttpBinding_IConexaApiService" />
</client>
</system.serviceModel>
</configuration>
And The relavant Server Code
<basicHttpBinding>
<binding name="BasicHttpEndpoint_MPSAPIServic" maxReceivedMessageSize="2000000">
<security mode="TransportWithMessageCredential" />
</binding>
<binding name="BasicHttpEndpoint_HelloService" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2000000">
</binding>
</basicHttpBinding>
<service name="IIS_test123.HelloService">
<endpoint address="ConexaApi" binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpoint_HelloService" contract="IIS_test123.IHelloService"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/API/ConexaApiService" />
</baseAddresses>
</host>
</service>
</services>
Any idea how to fix this?
This can be explainned. If you look at your exceptions:
System.ServiceModel.CommunicationException is an exception thrown from client side. It has the maxReceivedMessageSize from the client side. Everything is fine.
FaultException: this exception is a SOAP fault that propagate the exceptions from the service to the client application. ( http://www.codeproject.com/Articles/799258/WCF-Exception-FaultException-FaultContract). So this exception is actually coming from the service side! The maxReceivedMessageSize is the default value, and does not correspond to the maxReceivedMessageSize in your server configuration.
The address you are connecting to in your client is the service address, not configured maxReceivedMessageSize, and not the endpoint address ConexaApi which is configure with maxReceivedMessageSize="2000000". That' s why you are getting the default 65536.
And 4215 must be the size of your message if you consider that the exception does not raise if you increase it.
I have a windows service that hosts a WCF service. I have a client that consumes the service. The client does not recognize the ServiceReference1 even though I added it as a Service Reference.
I have been trying to fix this all day - I have read the code multiple times - I have used WCF before with no issues (in the same manner as this).
Interface
namespace ValidStateService
{
[ServiceContract]
public interface IValidStateWCFService
{
// Add two numbers
[OperationContract(IsOneWay = false)]
int AddNumbers(int numA, int numB);
}
}
Implementation of the Interface
namespace ValidStateService
{
public class ValidStateWCFService : IValidStateWCFService
{
// Call the agent to add two numbers and return the result
public int AddNumbers(int numA, int numB)
{
try
{
return 20; // Always return 20 for testing
}
catch (Exception ex)
{
return -1;
}
}
}
}
Windows Service App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="ValidStateService.ValidStateWCFService">
<endpoint address="" binding="basicHttpBinding" contract="ValidStateService.IValidStateWCFService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/ValidStateService/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Now on a Winform i have added reference to the service but servicereference1 is not recognized.
Code to add two numbers
*Winform App.config*
private void buttonGetDataFromAgent_Click(object sender, EventArgs e)
{
try
{
InstanceContext context = new InstanceContext(this);
ServiceReference1. // Winform App does not recognize this i.e no intellisense
??????
Client App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<client>
<endpoint address="http://localhost:8732/ValidStateService/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IValidStateWCFService"
contract="ServiceReference1.IValidStateWCFService" name="BasicHttpBinding_IValidStateWCFService" />
</client>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IValidStateWCFService" />
</basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>