Error in Window application when it will call WCF - c#

I have developed window application and in that i am calling WCF at particular time interval however there is no error in inserting data into database through WCF but in log entry i am getting one error regarding WCF Endpoint as per below
2011-22-09 10:16>>Error: There was no endpoint listening at
myserviceUrl(.svc) that could accept the message. This is often
caused by an incorrect address or SOAP action. See InnerException, if
present, for more details.
app.config file as per below and i guess that probably error should be in below configuration
<client>
<endpoint address="myserviceUrl(.svc)"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IApicaAzureMonitorAgentReceiverWCF"
contract="Dashboard2WCFData.IApicaAzureMonitorAgentReceiverWCF"
name="BasicHttpBinding_IApicaAzureMonitorAgentReceiverWCF" />
</client>
Below is my (WCF)service's configuration..
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</configSections>
<dataConfiguration defaultDatabase="Connectionstr"/>
<connectionStrings>
<add name="Connectionstr" connectionString="myconnectionstring"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Please help me to sort out of this issues.
Thanks.

You need to make sure that the endpoint is configured at the service side, not just your client. In other words, if the client uses myserviceUrl(.svc), the address needs to be specified in the service's config file.
Based on the error message you got, try this in the service's config file:
<endpoint address="myserviceUrl(.svc)"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IApicaAzureMonitorAgentReceiverWCF"
contract="Dashboard2WCFData.IApicaAzureMonitorAgentReceiverWCF"
name="BasicHttpBinding_IApicaAzureMonitorAgentReceiverWCF" />
Note that you'll need to ensure your service has the appropriate binding section named "BasicHttpBinding_IApicaAzureMonitorAgentReceiverWCF".
If you need a more thorough example, post your service's config file and we'll help you out.
UPDATE
Add an endpoint section, and a binding section if you have any values set to other than the default values:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="myServiceName">
<endpoint address="myserviceUrl(.svc)"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IApicaAzureMonitorAgentReceiverWCF"
contract="Dashboard2WCFData.IApicaAzureMonitorAgentReceiverWCF"
name="BasicHttpBinding_IApicaAzureMonitorAgentReceiverWCF"/>
<endpoint name="mexHttpBinding"
contract="IMetadataExchange"
binding="mexHttpBinding"
address="mex" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IApicaAzureMonitorAgentReceiverWCF" />
</basicHttpBinding>
</bindings>
In the <binding name="" section is where you'd set the values for the binding. If you don't do this (and don't specify the section in the endpoint's bindingConfiguration attribute) WCF will use the default values for basicHttpBinding.
NOTE: With WCF 4.0 and later, you actually don't need to specify an endpoint (or create a .svc file if hosting under IIS), as WCF will supply a default endpoint based on the URI of the service. See A Developer's Introduction to Windows Communication Foundation 4 for details on this and other new features in 4.0.

You need to specify in address attribute the whole virtual path
for example http://localhost/yousite/myservice.svc

Related

WCF not accessible from web

I have imported an a wcf service and it is accessible from local host but when I use my public ip address i am unable to reach it.
This is the contents of my web.config file.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"
targetFramework="4.0" />
</system.web>
<system.serviceModel>
<extensions>
<bindingExtensions>
<add name="clearUsernameBinding"
type="WebServices20.BindingExtenions.ClearUsernameCollectionElement, ClearUsernameBinding" />
</bindingExtensions>
<!-- Add the inspector attribute as a behavior for displaying SOAP XML packets -->
<behaviorExtensions>
<add name="consoleOutputBehavior"
type="WcfService1.ConsoleOutputBehaviorExtensionElement, WcfService1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
<bindings>
<clearUsernameBinding>
<binding name="myClearUsernameBinding"
messageVersion="Soap12" />
</clearUsernameBinding>
</bindings>
<behaviors>
<!-- Add the inspector behavior -->
<endpointBehaviors>
<behavior name="inspectorBehavior">
<consoleOutputBehavior />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="HelloWorldServiceBehavior">
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="WcfService1.CustomUserNameValidator, WcfService1" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="HelloWorldServiceBehavior"
name="WcfService1.HelloWorldService">
<endpoint address=""
binding="clearUsernameBinding"
bindingConfiguration="myClearUsernameBinding"
contract="WcfService1.IHelloWorldService" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
I have a console app that is able to communicate with it but ONLY with localhost.
This is how I am able to get to it. It is running on port 14946 and have port forwarded that port to the computer that has the service running. It is hosted on IIS.
http://localhost:14946/HelloWorldService.svc?singleWsd
If I use : {publicIP}:14946/HelloWorldService.svc?singleWsd
I get a 500 internal error which means its a configuration issue but I can't seem to pinpoint what the problem is.
EDIT: I am now receiving this error.
The type 'WcfService1.HelloWorldService', provided as the Service attribute value in the ServiceHost directive could not be found. I am able to get to it over the web now but receiving this error now. In order to fix the previous error I had to: 1.) Go to add remove features 2.) Expand MS .NET Framework 3.) Flip on both HTTP and Non-HTTP activation for WCF
Thanks,
If you properly hosted it in IIS you can just remove the port in endpoint and access it directly, something like this: ( add virtual application if necessary )
http://<public ip>/HelloWorldService.svc?singleWsd
It is working in your localhost because it was hosted in IIS Express upon debug mode and automatically assigned that port.

Error with WCF. Could not find a base address that matches scheme http for the endpoint with binding WSHttpBinding

I'm new to building Web Services and WCF in general, although I've done well so far I've ran into The following issue issue I can't seem to get past.
Could not find a base address that matches scheme http for the endpoint with binding WSHttpBinding. Registered base address schemes are [].
I have my app.config set up as such
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WcfSoapServiceBinding">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="WcfSoapServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="WcfSoapServiceBehavior" name="WcfSoapService.Service1">
<endpoint binding="wsHttpBinding" bindingConfiguration="WcfSoapServiceBinding"
contract="WcfSoapService.IService1" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
I set security mode to "None" so it uses HTTP instead of HTTPS and I also set the httpGetEnabled to true. I've tried some different options I've found online for some time, but none have helped so far. I'm using Ewald Hofman's example on how to use WCF to subscribe to TFS.
http://www.ewaldhofman.nl/post/2010/08/02/How-to-use-WCF-to-subscribe-to-the-TFS-2010-Event-Service-rolling-up-hours.aspx
I feel like I am close but this is the one thing I can't get past. My ultimate goal is to take the Soap Request from TFS and parse through its data. Being new to WCF and Web servers I'm unsure on what this error is actually telling me is wrong as well. So I have two questions.
1) What does this error mean is wrong? More specifically what does "Registered base address schemes are []" mean.
2) How could I go about fixing the error?
In your service section add base address or add address element for your endpoint.
<services>
<service behaviorConfiguration="WcfSoapServiceBehavior" name="WcfSoapService.Service1">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8182/MyService"/>
</baseAddresses>
</host>
<endpoint address=""
binding="wsHttpBinding" bindingConfiguration="WcfSoapServiceBinding"
contract="WcfSoapService.IService1" />
</service>

Facing issue with WCF: Could not find default endpoint

I created a WCF service in separate project name is AaWs then added this project in a website project as a reference . website project name is AaNuWs
in website project web.config file is
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata httpGetEnabled="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="mexBehavior" name="AaWs.RxtraIntroService">
<endpoint address ="AaWs" binding="basicHttpBinding" contract="AaWs.IRxIntro">
</endpoint>
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8080" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
then uploaded this website project on my web server.
then give the service reference in my new project from my website with a name space
IntroService
http://mywebsite/IntroService.svc?wsdl
new system create a new app.config file for me
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IRxIntro" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://mywebsite/IntroService.svc/RecoverInfoTechAaWs"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRxIntro"
contract="IntroService.IRxIntro" name="BasicHttpBinding_IRxIntro" />
</client>
</system.serviceModel>
</configuration>
but now when i trying to access this service i am getting a error.
System.InvalidOperationException: Could not find default endpoint
element that references contract 'IntroService.IRxIntro' 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.
please help me on this
You need to confirm that the app.config is in the root folder with your executable. Then confirm that the app.config has the proper value for:
<client>
<endpoint ... contract=""
From the information you provided, the address information does not look correct. Your service has an overall address of "http://localhost:8080/AaWs" but your service reference (wsdl url) shows "http://mywebsite/IntroService.svc?wsdl". You surely want to make sure that you are pointing to the correct service when generating the reference.
Remove name="BasicHttpBinding_IRxIntro" attribute from endpoint configuration of app.config.

WCF Won't Work Over HTTPS

I have looked through all of the other solutions and none of them are working. I am hosting a WCF service using IIS. The following is my web.config (the default for when I added a WCF service):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<customErrors mode="Off" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
All is good and I can access my wcf service in the browser using http://www.domain.com/path/service.svc and https://www.domain.com/path/service.svc - now I add a web reference to https://www.domain.com/path/service.svc in a windows console application and the following is in my app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="defaultBasicHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://www.domain.com/path/service.svc" binding="basicHttpBinding" bindingConfiguration="defaultBasicHttpBinding" contract="DomainExt.IExt" name="BasicHttpBinding_IExt" />
</client>
</system.serviceModel>
</configuration>
The following code is what I am using to test the service:
public static String DoPing()
{
ExtClient client = new ExtClient("BasicHttpBinding_IExt", "https://www.domain.com/path/service.svc");
return client.DoPing();
}
After I run this I get the following exception:
There was no endpoint listening at https://www.domain.com/path/service.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 sates:
"The remote server returned an error: (404) Not Found."
This service works fine over http but fails on https. How can I fix this? Please note that I'm accessing this service using Windows Console and NOT through ASP.NET; ASP.NET is only hosting the WCF service.
Try setting httpsGetEnabled="true" rather than httpGetEnabled
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpsGetEnabled="true" />
EDIT: I'm also curious why you chose the BasicHttpBinding if you're using SSL. Why not use the WsHttpBinding?
EDIT2: Are you missing a <services> node in your host config file? I wouldn't think you could create a client without one. You can right click on your app.config file and configure it there... Something like this:
<services>
<service behaviorConfiguration="MyServiceBehavior" name="MyService">
<endpoint address="" binding="defaultBasicHttpBinding" bindingConfiguration="basicBinding" contract="IMyService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">

c# binding error in WCF

I am getting the following error when trying to access a WCF service.
Could not find a base address that matches scheme http for the endpoint with binding MetadataExchangeHttpBinding. Registered base address schemes are [https].
Here's my config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DefaultHttpBinding"
maxBufferSize="655360"
maxReceivedMessageSize="655360">
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
<baseAddressPrefixFilters>
<add prefix="http://MySite.com/MyVirtualDir/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<services>
<service behaviorConfiguration="DefaultBehavior"
name="MyWcfService">
<endpoint address="http://MySite.com/MyVirtualDir/MyWcfService.svc"
binding="basicHttpBinding"
bindingConfiguration="DefaultHttpBinding"
contract="MyNamespace.IMyWcfService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
<serviceMetadata httpGetEnabled="true"
policyVersion="Policy15"/>
<serviceDebug httpHelpPageEnabled="true"
includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
And here's my .scv file
<%# ServiceHost Language="C#" Debug="true" Service="MyWcfService" Factory="MyWcfServiceHostFactory"%>
To give some more background that may or may not be helpful
The service works fine in our DEV environment. This error is only
occurring in our TEST and PROD environments. The only discernable
difference between environments that i am aware of is that TEST and PROD are using a
load balancer.
The service is hosted in IIS 5.1 on all environments
The service has been written in dot.net 3.5 and is activated by a
WebServiceHost factory
I have not specified https anywhere in my config file
SSL has NOT been enabled in IIS on any of the environments. Anonymous access has been enabled (security implementation will come later on).
Any help would be much appreciated as this is a complete show stopper for our project. I have throurghly searched the web for solutions to this problem, but nothing seems to relate to my my particular set up.
So for me, the fix for this issue was to remove the mex binding as per some of your suggestions. I also removed the servicemetadata section from the DefaultBehavior in config.
This fix only hides the original issue as I still have no idea why the mex binding was registered as https. But I can now consume my web service, even if i can't retrieve the metadata from it - that's not a problem in my case.
Here's the corrected config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DefaultHttpBinding"
maxBufferSize="655360"
maxReceivedMessageSize="655360">
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
<baseAddressPrefixFilters>
<add prefix="http://MySite.com/MyVirtualDir/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<services>
<service behaviorConfiguration="DefaultBehavior"
name="MyWcfService">
<endpoint address="http://MySite.com/MyVirtualDir/MyWcfService.svc"
binding="basicHttpBinding"
bindingConfiguration="DefaultHttpBinding"
contract="MyNamespace.IMyWcfService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
<serviceDebug httpHelpPageEnabled="true"
includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Try enabling tracing on your service to check why things fail in your test/production environment. To enable tracing check this link
Are you sure that the MyWcfServiceHostFactory doesnt have any code related to configuration (i.e. building configuration via c# code)

Categories

Resources