LightSwitch application chokes while instantiating a WCF proxy - vb.net

I'm trying to create a LightSwitch management panel for a web-based app. Thats why I was setting up a WCF RIA service to interface with the WCF service of the web app. While testing the loading of the users, I discovered that LightSwitch said that it couldn't load the resource. The Immediate Window told me that a System.InvalidOperationException had occured within System.ServiceModel.dll but VS didnt actually point me towards the loc where the error would have originated. After some line for line code execution, I discovered it choked at the instantiation of the WCF proxy.
An example of the code on the WCF RIA service Class:
Public Class RIAInterface
Inherits DomainService
Private WCFProxy As New Service.UserClient() '<-- Choke Point
Public Sub New()
WCFProxy.Open()
End Sub
<Query(IsDefault:=True)>
Public Function GetUsers() As IQueryable(Of User)
Dim TempList As New List(Of User)
For Each User As Service.User In WCFProxy.GetUsers()
TempList.Add(New User With {.ID = User.ID, .FullName = User.FullName, .EmailAddress = User.Email, .Username = User.UserName, .Class = User.Class.Name, .AccountType = User.Privilege.Name})
Next
Return TempList.AsQueryable
End Function
End Class
After some fooling arround with the RIA service and LightSwitch, something changed. I ran the app and got an actual exception.
Exception Details:
Could not find endpoint element with name 'EduNetBackEnd_IUser' and contract 'EduNet.IUser' 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.
This is the the ServiceModel configuration in the App.config:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="EduNetBackEnd_IUser" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:15:00"
enabled="true" />
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="[Service_Address]"
binding="wsHttpBinding" bindingConfiguration="EduNetBackEnd_IUser"
contract="EduNet.IUser" name="EduNetBackEnd_IUser" />
</client>
</system.serviceModel>

Related

UPN Identity for SOAP call getting switched in a clustered service

I make a call in which the WCF service client is constructed like so:
var endpointIdentity = EndpointIdentity.CreateUpnIdentity("DOMAINNAME\serviceAccountName#DOMAINNAME");
var endpointAddress = new EndpointAddress(theServiceUri, endpointIdentity);
var serviceClient = new ServiceReference.ServiceClient("WSHttpBinding_Service", endpointAddress);
The binding looks like this:
<wsHttpBinding>
<binding name="WSHttpBinding_Service"
closeTimeout="02:00:00"
openTimeout="02:00:00"
receiveTimeout="02:00:00"
sendTimeout="02:00:00"
bypassProxyOnLocal="false"
transactionFlow="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
messageEncoding="Text"
textEncoding="utf-8"
useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<reliableSession ordered="true"
inactivityTimeout="02:00:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
This code is running in a clustered service. When serviceClient calls one of its methods, I'm getting this error:
SOAP security negotiation with 'http://host-name:PORT/EndpointName' for target 'http://host-name:PORT/EndpointName' failed. See inner exception for more details. ---> System.ComponentModel.Win32Exception: Security Support Provider Interface (SSPI) authentication failed. The server may not be running in an account with identity 'host/host-name'. If the server is running in a service account (Network Service for example), specify the account's ServicePrincipalName as the identity in the EndpointAddress for the server. If the server is running in a user account, specify the account's UserPrincipalName as the identity in the EndpointAddress for the server.
Please note: the identity being used for the SOAP call is the host name (emphasized above), not DOMAINNAME\serviceAccount like it should, and like it does when I run through the debugger. What settings might be off on the server to cause this?
I checked the wsdl the service is publishing, and the wsdl:service block looks how I would expect:
<wsdl:service name="Service">
<wsdl:port name="WSHttpBinding_Service" binding="tns:WSHttpBinding_Service">
<soap12:address location="http://localhost:PORT/EndpointName"/>
<wsa10:EndpointReference>
<wsa10:Address>http://localhost:PORT/EndpointName</wsa10:Address>
<Identity xmlns="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
<Upn>serviceAccount#DOMAINNAME</Upn>
</Identity>
</wsa10:EndpointReference>
</wsdl:port>
</wsdl:service>

Programmatically adding an endpoint

I have a WCF service that I am connecting in client application. I am using following in configuration file.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyNameSpace.TestService" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:9100/TestService" binding="basicHttpBinding"
bindingConfiguration="MyNameSpace.TestService" contract="TestService.IService" name="MyNameSpace.TestService" />
</client>
</system.serviceModel>
In the code, I am calling API on this service as follows,
TestServiceClient client = new TestServiceClient()
client.BlahBlah()
Now I want to defined endpoint porgramatically. How can that be done? I commented out section from config file as I was thinking I will have to put some code on TestServiceClient instance to add endpoint dynamically but then it throws following exception at the point where TestServiceClient is instantiated.
Could not find default endpoint element that references contract
'TestService.IService' 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.
How can I accomplish this? Also any point on code examples for adding endpoint programmatically will be appreciated.
To create endpoints and bindings programmatically, you could do this on the service:
ServiceHost _host = new ServiceHost(typeof(TestService), null);
var _basicHttpBinding = new System.ServiceModel.basicHttpBinding();
//Modify your bindings settings if you wish, for example timeout values
_basicHttpBinding.OpenTimeout = new TimeSpan(4, 0, 0);
_basicHttpBinding.CloseTimeout = new TimeSpan(4, 0, 0);
_host.AddServiceEndpoint(_basicHttpBinding, "http://192.168.1.51/TestService.svc");
_host.Open();
You could also define multiple endpoints in your service config, and choose which one to connect to dynamically at run time.
On the client program you would then do this:
basicHttpBinding _binding = new basicHttpBinding();
EndpointAddress _endpoint = new EndpointAddress(new Uri("http://192.168.1.51/TestService.svc"));
TestServiceClient _client = new TestServiceClient(_binding, _endpoint);
_client.BlahBlah();
Can you just use:
TestServiceClient client = new TestServiceClient();
client.Endpoint.Address = new EndPointAddress("http://someurl");
client.BlahBlah();
Note that your binding configuration will no longer apply, as you're not using that endpoint configuration in your configuration file. You'll have to override that, too.
You can try:
TestServiceClient client = new TestServiceClient("MyNameSpace.TestService")
client.BlahBlah()
if not recheck namespace in file TestService is correct?

How do I consume a WS-Security service in WCF over HTTPS?

I'm trying to consume a WS-Security enabled service with WCF. Authentication works using a UsernameToken. I'm not very knowledgeable with WCF web service clients, but I think my configuration below works for regular HTTP communication. I (mostly) used this guide to configure it. The main difference is that I used the VS2010 "Add Service Reference" UI instead of a command prompt.
My problem is that I need to do this over HTTPS. When I use <security mode="Message"> in my app.config, I believe my soap envelope contains the needed WS-Security headers. I can't tell for sure because I can't get logging to work. However, I get the following error: The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via.
Below are the contents of my app.config file, as well as a sample of my client code.
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="Omitted" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Message">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" negotiateServiceCredential="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://omitted.com/service" binding="wsHttpBinding" bindingConfiguration="Omitted" contract="Omitted.Omitted" name="Omitted" />
</client>
</system.serviceModel>
var service = new OmittedClient();
service.ClientCredentials.UserName.UserName = "username";
service.ClientCredentials.UserName.Password = "password";
var response = service.DoSomething(new DoSomethingRequest());
Thanks to 500 - Internal Server error for helping me figure it out. Here are the steps I took:
Generate a proxy using Visual Studio/WCF.
Change the security mode to TransportWithmessageCredential.
Use the following code to specify a username/password.
var client = new WebServiceClient();
client.ClientCredentials.UserName.UserName = "USERNAME";
client.ClientCredentials.UserName.Password = "PASSWORD";
If you get a response back, but WCF complains when processing it, there might be a timestamp missing from the response. If that's the case, try this to fix it.
// WCF complains about a missing timestamp (http://www.west-wind.com/weblog/posts/2007/Dec/09/Tracing-WCF-Messages)
var elements = service.Endpoint.Binding.CreateBindingElements();
elements.Find().IncludeTimestamp = false;
service.Endpoint.Binding = new CustomBinding(elements);

Trying to call WCF service from inside NServiceBus Message Handler, but it hangs when creating the Service Client

Must be doing something awfully wrong here. Here is what I'm trying to do.
I have a Message handler that should get a message from the queue. Make a WCF call, do stuff and when done, send a new message out on the bus.
It is hosted in the NServiceBus.Host.Exe.
But, whenever I create the Service Client, eveything comes to a grinding halt. If I comment out the service call everything works great... Except, I need that call.
Is there a trick I must do to make WCF calls from my Message Handler when hosting it in the NServiceBus.Host.Exe? I have not made any special config in the EndPointConfig class.
public class EndpointConfig :
IConfigureThisEndpoint, AsA_Server { }
public class RequestAccountUpdateMessageHandler : IHandleMessages<RequestAccountUpdateMessage>
{
public void Handle(RequestAccountUpdateMessage message)
{
// The Line below hangs everything
AccountService.AccountServiceClient client =
new AccountService.AccountServiceClient();
resp = client.DoStuff(message.parameter);
Bus.Send<UpdateAccountMessage>(m =>
{
m.info = DoMagicStuffHere(resp);
});
}
...
}
This is what the system.serviceModel looks like in the App.Config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IAccountService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://yadayafa/accountservice.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAccountService" contract="AccountService.IAccountService" name="BasicHttpBinding_IAccountService"/>
</client>
</system.serviceModel>

Issue in calling WCF Service that calls another WCF Service

We have a requirement to call a WCF service from another WCF Service. To test this I build a sample console application to display a simple string. The setup is:
Console App -> WCF Service 1 -> WCF Service 2
Console App calls a method of service 1 and the service 1 method eventually calls service 2 method to return a string. I am able to call Console -> Service 1 but Service 1 -> Service 2 is not working. It throws an exception:
"Could not find default endpoint element that references contract 'ITestService2' 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."
To accomplish this, I have created a WCF Service 2 with one method that returns a string (nothing fancy).
namespace TestServices
{
[ServiceContract]
public interface ITestService2
{
[OperationContract]
string GetSomething(string s);
}
}
Then I create service1 - ITestService1.cs and TestService1.cs that consumes service2 method GetSomething().
namespace TestServices
{
[ServiceContract]
public interface ITestService1
{
[OperationContract]
string GetMessage(string s);
}
}
namespace TestServices
{
class TestService1 : ITestService1
{
public string GetMessage(string s)
{
TestService2 client = new TestService2();
return client.GetSomething("WELCOME " + s);
}
}
}
Note: I create a proxy for Service2 using svcutil.exe. It creates a app.config and TestService2.cs files that I copied in TestService1 project folder to reference.
Finally, I created the console app that just creates an instance of Service1 and calls the GetMessage() method.
static void Main(string[] args)
{
TestService1 client = new TestService1();
Console.WriteLine(client.GetMessage("Roger Harper"));
Console.ReadKey();
}
When I call the service 2 directly from Console application, it works without any issue. The same config and proxy class when copied with in service 1. It throws error. The config file looks like:
config file for service 1 in console application:
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ITestService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:3227/WCFTestSite/TestService1.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ITestService1"
contract="ITestService1" name="WSHttpBinding_ITestService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
config file for service 2 in service1 folder:
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ITestService2" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:3227/WCFTestSite/TestService2.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ISriWCFTestService2"
contract="ITestService2" name="WSHttpBinding_ITestService2">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Appreciate if someone can help me in resolving this issue. I also tried prefixing the contract name with namespace but it didn't work. Not sure how the same config/proxy works directly from console and not with in another service. Please HELP!!! Thanks in advance.
From my understating you have a console app that is self hosting a wcf service that service is calling a second wcf service. I am guessing you have a wcf service1 defined in dll that the console app loads and then attempts to call. I think your issue may be that sice service 1 is in a dll its not loading the config file where you have defined the link to service 2. Try creating the endpoint programmaticly and see if that gets you thorough the issue.