I wrote a Wcf Service and its configuration file is
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="securityDemo">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="WcfDemo.EmpService" behaviorConfiguration="MyServiceTypeBehaviors">
<host>
<baseAddresses>
<add baseAddress="http://localhost:3003/"/>
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding" contract="WcfDemo.IEmpService" bindingConfiguration="securityDemo"/>
</service>
</services>
</system.serviceModel>
This working fine for a console app or WPF app.
But when I am using same service for windows 8.1 app i am getting this exception
The HTTP request is unauthorized with client authentication scheme
'Negotiate'. The authentication header received from the server was
'Negotiate,NTLM'.
Deploy a WCF service on IIS Local (because IIS Express are not so flexible), set off Anonymous Authentication and set on Windows Integrated Authentication.
make service reference in target Win 8 app.
before using Service proxy add a lines with identification:
var client = new ServiceReference1.Service1Client();
client.ClientCredentials.Windows.ClientCredential.UserName = "windows user name";
client.ClientCredentials.Windows.ClientCredential.Password = "user passw";
call a service method
profit
Related
I have a Windows CE 5.0 app created in Visual Studio 2008. This app references a service, which is a WCF Service created in Visual Studio 2010 and hosted in IIS 6. Since the service is referenced from a Windows CE project, it is referenced as a legacy web service using the Add Web Reference dialog.
The service is configured to use Transport security and it expects Windows credentials:
<system.serviceModel>
<services>
<service name="ServiceTests.TestService">
<endpoint address="" binding="basicHttpBinding" contract="ServiceTests.ITestService" bindingConfiguration="basicConfig"></endpoint>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicConfig">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Windows"></transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
This service is easily consumed from a normal .net 4.0 app as below:
var client = new TestServiceClient();
client.ClientCredentials.UserName.UserName = "FBradley";
client.ClientCredentials.UserName.Password = "jgb.2013!";
System.Console.WriteLine(client.GetData(1));
System.Console.ReadLine();
However, from the Windows CE project the ClientCredentials property is not available, only a Credentials property. I have attempted to pass a NetworkCredential type to it but it fails:
using (var client = new TestService())
{
client.Credentials = new NetworkCredential("usename", "password", "domain");
var response = client.GetData(1, true);
MessageBox.Show(response);
}
Am I leaving out something from the service config file that the Windows CE device (which is obviously not a member of the domain) needs to authenticate? How can I configure this Windows CE (non-domain) device or the service so that the client can consume the service? What am I missing?
I am trying to add a client for a WCF service that is net.tcp based. When I use "Add Service Reference" and provide this URL:net.tcp://localhost/service1.svc, it gives following error.
The URI prefix is not recognized. Metadata contains a reference that
cannot be resolved: 'net.tcp://localhost/service1.svc'. Could not
connect to net.tcp://localhost/service1.svc. The connection attempt
lasted for a time span of 00:00:02.0051147. TCP error code 10061: No
connection could be made because the target machine actively refused
it 127.0.0.1:808. No connection could be made because the target
machine actively refused it 127.0.0.1:808 If the service is defined in
the current solution, try building the solution and adding the service
reference again.
I checked Windows Components for WCF non-http services, but they are already installed. This is the snap:
As you can see they are installed for .NET 3.5.1 and my service is built in .NET 4.5. Is this the problem? And how should I solve it? Because there is no option for .NET 4.5 in Windows Components List.
Following is the configuration of my WCF service:
<system.serviceModel>
<services>
<service name="CoreService.Service1" behaviorConfiguration="beh1">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost/Service1.svc"/>
</baseAddresses>
</host>
<endpoint
binding="netTcpBinding"
bindingConfiguration="ultra"
contract="CoreService.IAccountService"/>
<endpoint
binding="netTcpBinding"
bindingConfiguration="ultra"
contract="CoreService.ICategoryService"/>
<endpoint
binding="netTcpBinding"
bindingConfiguration="ultra"
contract="CoreService.ICommonService"/>
<endpoint
binding="netTcpBinding"
bindingConfiguration="ultra"
contract="CoreService.IFollowerService"/>
<endpoint
binding="netTcpBinding"
bindingConfiguration="ultra"
contract="CoreService.IInterestService"/>
<endpoint
binding="netTcpBinding"
bindingConfiguration="ultra"
contract="CoreService.IInviteService"/>
<endpoint
address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="ultra"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
maxConnections="2147483647"
maxReceivedMessageSize="2147483647"
portSharingEnabled="false"
transactionFlow="false"
listenBacklog="2147483647"
sendTimeout="00:01:00">
<security mode="None">
<message clientCredentialType="None"/>
<transport protectionLevel="None" clientCredentialType="None"/>
</security>
<reliableSession enabled="false"/>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="beh1">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="True" />
<dataContractSerializer maxItemsInObjectGraph="65536" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
It doesn't seem an incompatibility issue between the WCF HTTP or Non-HTTP Activation features and your service.
According to me, there's a missing or wrong configuration in IIS and that would explain the refused connection. To configure properly IIS with with net.tcp, have a look here.
I have WCF Service hosted on my computer (not on IIS). This service works fine, when I call it funnction from VS 2010. But if I want to call some method from Windows Mobile device i receive following error: There was no endpoint listening at....
My config of services is:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="DataSource" value="CMP\DATABASE" />
<add key="DataName" value="DAT" />
</appSettings>
<system.web>
<compilation debug="true"/>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<bindings>
<mexHttpBinding>
<binding name="MexBinding"/>
</mexHttpBinding>
<basicHttpBinding>
<binding name="Binding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<!-- UsernameToken over Transport Security -->
<!--<security mode="Transport">
<message clientCredentialType="Certificate" />
</security>-->
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Test.Service" behaviorConfiguration="Test.ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://10.0.0.2:1918/Myservice/Service/"/>
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<!--<endpoint address="" binding="wsHttpBinding" contract="WcfServiceLibrary.IService">
-->
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<!--
<identity>
<dns value="localhost" />
</identity>
</endpoint>-->
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="ServiceA" binding="basicHttpBinding" bindingConfiguration="Binding" name="Service" bindingName="Binding" contract="Test.IService"/>
</service>
</services>
<!--<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>-->
<behaviors>
<serviceBehaviors>
<behavior name="Test.ServiceBehavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<!--<serviceAuthorization principalPermissionMode="None" />-->
<!-- 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>
</system.serviceModel>
</configuration>
I don't have set proxy on my mobile device.
You're using HttpBinding so some type of webserver is running on your box allowing the WCF hosting to work locally. So that's Cassini or IIS Express. Neither allows for remote connections without a bit of tweaking. Here's link of how to do that for IIS Express http://johan.driessen.se/posts/Accessing-an-IIS-Express-site-from-a-remote-computer but it's a bit tedious though possible. I don't know if it's possible to allow Cassini to have remote connections.
I am having a WCF ServiceLibrary which runs successfully on WCF Test Client.
Now I am trying to build a Website to Host this web service. I am using nettcp binding. My web.config file looks like this
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="tcp_Unsecured" portSharingEnabled="true">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="tcpServiceBehavior" name="MarketFeedServiceLibrary.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="tcp_Unsecured"
name="data" contract="MarketFeedServiceLibrary.IService1" />
<endpoint address="mextcp" binding="mexTcpBinding" name="metadata"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="tcpServiceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
I am try to view in browser directly from Solution Explorer
But I get error as shown below
Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].
I have tried all the solutions available on SO, youtube etc but no luck,
I tried:
Under IIS I have enabled http,net.tcp protocols
I have also gone through: How to: Install and Configure WCF Activation Components
N.B. I am a WPF App Developer, hence WCF and ASP.NET Website are new to me.
Thank You.
Edit: Testing Under WCF Client gives following error
Cannot obtain Metadata from net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. WS-Metadata Exchange Error URI: net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc'. Could not connect to net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc. The connection attempt lasted for a time span of 00:00:01.9968000. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8080. No connection could be made because the target machine actively refused it 127.0.0.1:8080
I'm developing a WCF Service with a custom UserNamePasswordValidatorwith a basicHttpBinding. This configuration, however, works only on HTTPS binding. Since Visual Studio 2010's built in web server does not support https, how can I test my custom validator? I keep getting Could not find a base address that matches scheme https for the endpoint with binding BasicHttpBinding. Registered base address schemes are [http]. error and, if I set the clientCredentialType to none, the error is gone, but the validator does not get called.
Below is my configuration.
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="ServiceErrorHandler" type="company.application.appserver.implementation.ServiceErrorHandlerBehaviorExtensionElement, AppSoftAppServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
<bindings>
<basicHttpBinding>
<binding name="SimpleBinding">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="DefaultBehavior" name="company.application.appserver.implementation.AppSoftUpdate">
<endpoint address="udt" binding="basicHttpBinding" bindingConfiguration="SimpleBinding"
name="AppSoftUpdate" bindingNamespace="http://company.application/update/2011/04"
contract="company.application.appserver.interfaces.IAppSoftUpdate" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
name="AppSoftUpdateMex" bindingNamespace="http://company.application/update/2011/04"
contract="IMetadataExchange" />
</service>
<service behaviorConfiguration="DefaultBehavior" name="company.application.appserver.implementation.AppSoftTransaction">
<endpoint address="udt" binding="basicHttpBinding" bindingConfiguration="SimpleBinding"
name="AppSoftTransacao" bindingNamespace="http://company.application/transaction/2011/04"
contract="company.application.appserver.interfaces.IAppSoftTransacao" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
name="AppSoftTransacaoMex" bindingNamespace="http://company.application/transaction/2011/04"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
<serviceMetadata httpGetEnabled="true" httpGetBinding="webHttpBinding"
httpGetBindingConfiguration="" />
<serviceDebug includeExceptionDetailInFaults="true" />
<ServiceErrorHandler />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType=" company.application.appserver.implementation.AppSoftValidacaoLogin, AppSoftAppServer" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Use IIS for this testing.
Open your project properties, go to the Web tab, hit Use local IIS radio button. This manual is valid for VS2010 too: Using Visual Studio 2008 with IIS 7
If IIS is not installed yet, install it first: How to install IIS.
You need to have Windows edition higher than Windows Home.
You will also need to create a self-signed certificate for your web site. This is easy to do in IIS 7: Self-Signed Certificates on IIS 7 – the Easy Way and the Most Effective Way
You cannot test such WCF service in Cassine (built-in web server in VS 2010). You must use local IIS or install VS 2010 SP1 and download IIS Express which is lightweight web server for development (can replace Cassini in VS and supports HTTPS with self signed certificates). IIS Express doesn't need any specific Windows edition and it works on all versions since Windows XP but it provides same features as IIS 7.5.