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.
Related
I've been facing a tough issue for three days. I have a WCF web api (.svc service file) deployed to an IIS 8.5. The application was working properly and then, suddenly, after I changed some other minor things inside the code, this problem arises: I can connect to the application from inside the server (using localhost). I can connect from outside, using the server IP address. But I cannot, by any means, connect from the outside by using server hostname. The problem is best understood through the examples bellow:
Note: the application is an IIS app inside the main Web Site. The service's URI is http://myhostname/api/servicos.svc
http://localhost/api/servico/some_request: works!
http://server_ip_address/api/servico/some_request: works!
http://myhostname.com/api/servico/some_request: DOES NOT WORK!
I have searched through many websites and forums but of no avail.
My web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<customErrors mode="Off" />
</system.web>
<connectionStrings>
<!-- My connection string goes here -->
</connectionStrings>
<system.serviceModel>
<services>
<service name="ServicoWeb.servico" behaviorConfiguration="Wcf_Behavior">
<endpoint name="" binding="webHttpBinding" contract="ServicoWeb.IServico" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp automaticFormatSelectionEnabled="true" defaultBodyStyle="Bare" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Wcf_Behavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="removeSvcDaUrl" type="ServicoWeb.Validacao.UrlCustomizacao, ServicoWeb" />
</modules>
<directoryBrowse enabled="true" />
<rewrite>
<rules>
<remove name="WordPress: https://myhostname.com" />
</rules>
</rewrite>
<handlers accessPolicy="Read, Execute, Script" />
<security>
<requestFiltering>
<verbs>
<add verb="*" allowed="true" />
</verbs>
</requestFiltering>
</security>
</system.webServer>
</configuration>
The error I am presented to when trying to access the API from outside (via hostname) is this:
Server Error in '/Api' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make
sure that it is spelled correctly.
Requested URL: /Api/servico.svc/asos/csv/09655055000104
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.6.1069.1
Do you have any idea what should I do in order to fix this bug?
Edit: one more information: other apps inside the same web site in IIS works FINE! There are even other web apis written in C#, just like this one here, and they all work properly.
Edit 2: another thing important to say is that I can access the service path until the service itself (servico.svc). So, for example, when I try to access "http://myhostname.com/api/servico.svc?wsdl" I successfully get the service's metadata. So, only when I try to access the service itself I get the error mentioned above.
There is a file named host file. When you try request a DN windows look into that file. That file inside C:\WINDOWS\System32\drivers\etc there is host file. Append like below this in your host file (with admin mode).
server_ip_address myhostname.com
I finally got it solved! For those struggling with this issue without sucess: Amazon EC2 load balance was the cause of my troubles.
It happened that Load Balance was set up to filter all requests and send them to the server machines using transport layer SSL security protocol (HTTPS). So, if I were to request http://myserver.com/servico Amazon Load Balance would internally redirect to https://machine-n/servico where 'n' is the machine used (in my case, I have two machines).
So, what caused my issue, inside WCF, was this: my web.config was not allowing the service to accept HTTPS requests. Once I fixed this, everything worked fine.
It also explains why everything worked when I requested directly using the machine's IP address using HTTP: load balance did not play any role in this case filtering the request and redireting using HTTPS.
So, here we have my web.config, now allowing HTTPS requests:
<?xml version="1.0" encoding="UTF-8"?>
...
<system.serviceModel>
<services>
<service name="ServicoWeb.servico" behaviorConfiguration="Wcf_Behavior">
<endpoint name="" binding="webHttpBinding" contract="IServico" bindingConfiguration="webHttpTransportSecurity" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webHttpTransportSecurity">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp automaticFormatSelectionEnabled="true" defaultBodyStyle="Bare" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Wcf_Behavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
...
In my case below things helped :
Check protocolMapping is binded correctly.
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
Check 443 port is open and working.
Hi I am developing small application using WCF,MVC4 and angularJS. I am refering following URL
https://code.msdn.microsoft.com/AngularJS-Shopping-Cart-8d4dde90#content
When i tried to add service reference in my mvc application I am getting below error
Metadata publishing for this service is currently disabled.
I gave below url to access service.
http://localhost:55835/Service1.svc
When i tried I am getting error. I am unable to add service reference in my application. I am little worried about my web.config file. This is my web.config file.
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp helpEnabled="True"/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="webHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Can someone tell me something I am missing anything in config file?
Thank you in advance.
This problem is displaying because you are not enabling metadata.Metadata(wsdl document for your service code) is neccessary because your client will generate proxy class on the basis of your metadata(wsdl code). If you will not enable your metadata then your client will never know how to implement the same kind of code in its's proxy classes.And this can be enabled under servicemetadata tag under servicebehavior tag by setting httpGetEnabled to true.
Add this line of code under servicebehavior tag just after </endpointBehaviors> tag.(please do not include <behaviour> tag again)
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" httpGetUrl="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
We already created an webservice in Visual Studio 2013 with .Net 4.5. This webservice runs well local in the same computer.
Right now we want to export this webservice to an Windows Server 2008 with IIS. We already made an webservice running in port 8080.
But when we copy the exported files to the root directory of this webserver the folowwing error occured:
Error Summary
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Detailed Error Information
Module
IIS Web Core
Notification
Unknown
Handler
Not yet determined
Error Code
0x80070032
Config Error
The configuration section 'system.serviceModel' cannot be read because it is missing a section declaration
Config File
\\?\C:\inetpub\wwwroot\YOR24Websevices\web.config
Requested URL
http://localhost:8080/
Physical Path
Logon Method
Not yet determined
Logon User
Not yet determined
Config Source 10: </system.web>
11: <system.serviceModel>
12: <bindings>
The webconfig we exported in Visual studio is:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="RightNowSyncBinding">
<security defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport"
requireDerivedKeys="true" securityHeaderLayout="Lax" includeTimestamp="false">
<localClientSettings detectReplays="false" />
<localServiceSettings detectReplays="false" />
</security>
<textMessageEncoding messageVersion="Soap12" />
<httpsTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="https://tkbc-fleetsupport--tst.custhelp.com/cgi-bin/tkbc-fleetsupport--tst.cfg/services/soap"
binding="customBinding" bindingConfiguration="RightNowSyncBinding"
contract="RightNowServiceReference.RightNowSyncPort" name="RightNowSyncPort" />
</client>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Yor24Service.Service">
<endpoint address="" contract="Yor24Service.IService" binding="basicHttpBinding"/>
<endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding"/>
</service>
</services>
<protocolMapping>
<add binding="basicHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
What is the problem with this generated config file?
Starting with .Net Framework 4 service behaviors do not require a name (MSDN). Before .Net 4 it was mandatory. Because your service behavior does not have a name:
<serviceBehaviors>
<behavior>
<!-- name attribute missing in behavior -->
</behavior>
</serviceBehaviors>
and IIS is throwing an error I suspect your app pool is not running .Net 4 or newer.
http://blogs.msdn.com/b/wenlong/archive/2010/11/23/why-does-machine-config-contain-invalid-xml-content-after-installing-net-3-5-patches.aspx
Try this link, solution 3 work with me
Solution 3: Run attached javascript file
The above solutions do not fix the Issue 3. So I created a javascript FixServiceModel30Reg.js to fix the problem. You can run it as following to fix all of the above issues. Steps:
· Download the script FixServiceModel30Reg.txt and save it to the root of c: drive.
· Rename it to FixServiceModel30Reg.js.
· Open the Command Prompt window and run the following command:
Cscript.exe c:\FixServiceModel30Reg.js
I have rambled through net but dint find any solution.
Now The WCF services works perfectly on local whereas on remote server it throws 401 (Unauthorized) web exception for POST calls. GETs work fine.
Implementation Details :
On the Remote Server-
IIS : 6.0
.NET : 4.0
Calling App : WPF app.
On the Local Server-
IIS : 7.0
.NET : 4.0
Calling App : WPF app.
The service has Anonymous access specified for the WCF rest in the web.config.
For authentication We have implemented a AuthManager class which authenticates the request using hardcoded usernames and passwords.
While calling the caller adds the network credentials.
The header when i call the local network is:
Authorization: Basic dG9ueXXXXXXX
Whereas while calling server :
Authorization: Negotiate TlRMTVNTUAABAAAAl4IIXXXXXXX
This is what is looking fishy for me .
Below given is the Web.config of the Service :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<connectionStrings>
<add name="SqlServerConnectionString" connectionString="Data Source=BHUVINT\SQL2008R2;Initial Catalog=CPNS;User ID=sa;Password=orion#123"/>
</connectionStrings>
<system.diagnostics>
<trace>
<listeners>
<add name="myListener"
type="System.Diagnostics.EventLogTraceListener"
initializeData="Application" />
</listeners>
</trace>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<machineKey decryption="AES" decryptionKey="0CA3EFAF0F7A5E7A62681C0BF656EE0ECE31ACEE3E1023BA3FAD20EA5F199DE8" validation="SHA1" validationKey="3E4528C0FFE94A75DF02052B358BD9DE40800DD89DE62168764FF0DCE537184F0535D5D9AD66DEDC97DC1ABFF7FA540B4DFD82E5BB196B95D15FF81F75AD5328" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Mg">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="Mg" name="ApmWcfServiceWebRole.Push">
<endpoint binding="webHttpBinding" name="firstBinding" contract="ApmWcfServiceWebRole.IPushService" />
</service>
<service behaviorConfiguration="Mg" name="ApmWcfServiceWebRole.WP7Device">
<endpoint binding="webHttpBinding" name="secondBinding" contract="ApmWcfServiceWebRole.IWP7Service" />
</service>
<service behaviorConfiguration="Mg" name="ApmWcfServiceWebRole.iOSDevice">
<endpoint binding="webHttpBinding" name="thirdBinding" contract="ApmWcfServiceWebRole.IIOSService" />
</service>
<service behaviorConfiguration="Mg" name="ApmWcfServiceWebRole.AndroidDevice">
<endpoint binding="webHttpBinding" name="fourthBinding" contract="ApmWcfServiceWebRole.IAndroidService" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
</serviceHostingEnvironment>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
EDIT :
The AuthManager is called only wherein the POSTs are being made wherein the checks are required , And these are the ones which are failing.
EDIT 2:
I added a Trace in the AuthManager , The credentials are not received by it , its getting a blank value. Seems the issue is with passing credentials.
Thanks in advance.
The Issue is Solved :
I had enabled Anonymous access , but it had a check enabled on Windows Authentication which i removed and it started working
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)