We have a RIA Services call that only passes a couple of parameters, however it can take an extended period of time to process (e.g. 20+ minutes) When it hits around the 10 to 15 minute mark, we get an Error 404 Not Found exception. Here are the things we've done so far to take care of any timeout issues:
WebConfig - ServerSide
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<bindings>
<basicHttpBinding>
<binding name="" closeTimeout="01:00:00" openTimeout="01:00:00"
receiveTimeout="01:00:00" sendTimeout="01:00:00" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="Transport"/>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
Changed the WcfTimeouts:
public static class DomainContextExtensions
{
public static void ChangeWcfTimeouts(this DomainContext context)
{
PropertyInfo channelFactoryProperty =
context.DomainClient.GetType().GetProperty("ChannelFactory");
if (channelFactoryProperty == null)
{
throw new InvalidOperationException(
"There is no 'ChannelFactory' property on the DomainClient.");
}
TimeSpan timeout = new TimeSpan(1, 0, 0); // 1 Hour
ChannelFactory factory = (ChannelFactory)channelFactoryProperty.GetValue(context.DomainClient, null);
factory.Endpoint.Binding.SendTimeout = timeout;
factory.Endpoint.Binding.CloseTimeout = timeout;
factory.Endpoint.Binding.OpenTimeout = timeout;
factory.Endpoint.Binding.ReceiveTimeout = timeout;
}
}
Neither seems to affect the issue. Any and all ideas are welcome!
Related
I am trying to get a file upload/download via a WCF service working. The transfer protocol is HTTP. I have set the binding up to user Streaming as transfer mode and have tried for days now to get it working properly, without success. I have managed to get it working for small files. When uploading large files, the file is created on the server, a number of bytes are written and then the transaction fails.
The service is hosted in a Windows Azure WebRole environment scaled to a degree which must definitely be sufficient for the task.
When inspecting the trace log with (e2e-file) with SvcTraceViewer.exe, the problem seems to be this:
An exception has been thrown when reading the stream.
with the call stack:
System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream.Read(Byte[] buffer, Int32 offset, Int32 count)
DataService.TransferService.UploadFile(RemoteFileInfo request)
SyncInvokeUploadImage(Object , Object[] , Object[] )
System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
The service contract looks like this:
[ServiceContract]
public interface ITransferService
{
[OperationContract]
RemoteFileInfo DownloadImage(DownloadRequest request);
[OperationContract(IsOneWay = true)]
void UploadImage(RemoteFileInfo request);
}
[MessageContract]
public class DownloadRequest
{
[MessageBodyMember]
public string FileName;
}
[MessageContract]
public class RemoteFileInfo : IDisposable
{
[MessageHeader(MustUnderstand = true)]
public string FileName;
[MessageHeader(MustUnderstand = true)]
public long Length;
[MessageBodyMember(Order = 1)]
public System.IO.Stream FileByteStream;
public void Dispose()
{
if (FileByteStream != null)
{
FileByteStream.Close();
FileByteStream = null;
}
}
}
Here is the service implementation:
public class TransferService : ITransferService
{
public RemoteFileInfo DownloadImage(DownloadRequest request)
{
return DownloadFile(request);
}
public void UploadImage(RemoteFileInfo request)
{
UploadFile(request);
}
public RemoteFileInfo DownloadFile(DownloadRequest request)
{
var result = new RemoteFileInfo();
try
{
var filePath = Path.Combine(RoleEnvironment.GetLocalResource("TempStorage").RootPath, request.FileName);
var fileInfo = new FileInfo(filePath);
if (!fileInfo.Exists)
throw new FileNotFoundException("File not found", request.FileName);
var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
result.FileName = request.FileName;
result.Length = fileInfo.Length;
result.FileByteStream = stream;
}
catch (Exception ex)
{
}
return result;
}
public void UploadFile(RemoteFileInfo request)
{
FileStream targetStream;
var sourceStream = request.FileByteStream;
var filePath = Path.Combine(RoleEnvironment.GetLocalResource("TempStorage").RootPath, request.FileName);
using (targetStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
const int bufferLen = 65000;
var buffer = new byte[bufferLen];
var count = 0;
while ((count = sourceStream.Read(buffer, 0, bufferLen)) > 0)
{
targetStream.Write(buffer, 0, count);
}
targetStream.Close();
sourceStream.Close();
}
}
}
I've set the web.config of the WCF service up like this to enable streaming, increase the relevant size limitations (or at least the ones I know of) and the timeouts:
<?xml version="1.0"?>
<configuration>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="sdt"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "log.e2e" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.web>
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="2097151" useFullyQualifiedRedirectUrl="true" executionTimeout="14400" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<basicHttpBinding>
<binding closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:10:00"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"
transferMode="Streamed" >
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
The client side is a WPF application. The calling code is this:
private void UploadImage(byte[] data, Guid guid)
{
using (var transferService = new TransferServiceClient())
using (var stream = new MemoryStream(data))
{
var uploadRequestInfo = new RemoteFileInfo();
uploadRequestInfo.FileName = guid.ToString();
uploadRequestInfo.Length = data.Length;
uploadRequestInfo.FileByteStream = stream;
transferService.UploadImage(uploadRequestInfo);
}
}
private byte[] DownloadImage(Guid guid)
{
using (var transferService = new TransferServiceClient())
{
try
{
var request = new DownloadRequest(guid.ToString());
var iconFile = transferService.DownloadImage(request);
var data = ByteArrayOperations.FromStream(iconFile.FileByteStream);
return data;
}
catch (Exception)
{
return null;
}
}
}
and - finally - the client side app.config:
<?xml version="1.0"?>
<configuration>
<configSections>
<system.web>
<httpRuntime maxRequestLength="2097150"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ITransferService"
closeTimeout="04:01:00"
openTimeout="04:01:00"
receiveTimeout="04:10:00"
sendTimeout="04:01:00"
allowCookies="false"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
messageEncoding="Text"
textEncoding="utf-8"
transferMode="Streamed"
useDefaultWebProxy="true">
<readerQuotas maxDepth="128"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="xxx/TransferService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITransferService"
contract="Transfer.ITransferService" name="BasicHttpBinding_ITransferService" />
</client>
</system.serviceModel>
</configuration>
Note that out of desparation I've added this section:
<system.web>
<httpRuntime maxRequestLength="2097150"/>
</system.web>
without any effect.
In the error log there is one more exception being thrown directly after starting up the service. I neither know what it means nor whether it is related to the problem at all:
System.ServiceModel.ProtocolException
Content Type multipart/related;
type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:b230e809-500b-4217-a08e-32ff49e13bac+id=5";start-info="text/xml"
was sent to a service expecting text/xml; charset=utf-8. The client
and service bindings may be mismatched.
I've spent days getting this to work and really don't know what else I can try. I would be really really happy if somebody could have a look at the configs and maybe give a hint what else to try. So, the question is:
What could be the cause for the transfer to fail and what can I do to solve this?
I would also be happy for further advice on
What to do to find the root problem here, if it cannot be identified based on the information given in the question?
Appendix: I don't think the client side exception is of any use but I would like to include it in the question to make it easier for others with the same problem to find the answers to come (hopefully):
A first chance exception of type 'System.Net.Sockets.SocketException'
occurred in System.dll
Additional information: An existing connection was forcibly closed by
the remote host
I do not see where the service binding is being specified in the serivce config file. I suspect that the configuration values are not being read and this to be the cause of why.
So I propose specifying the name of the binding in the service config file as BasicHttpBinding_ITransferService (same name used in the client config) and then adding the following under the system.serviceModel node of the configuration file:
<services>
<service name="TransferService" >
<endpoint
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ITransferService"
contract="Transfer.ITransferService" />
</service>
</services>
Again strange issue to me.
After I refocused my wcf from http to https, when I try to call .svc methods not from UI, I started to get this exception "Could not establish trust relationship for the SSL/TLS secure channel with authority 'localhost' issue".
Also in InnerException I got this: "The remote certificate is invalid according to the validation procedure".
I have:
FunctionalApplicationBlock.InitializeWithShielding("BusinessServices Application");
if (Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("SkipServerCertificateValidation") == "true")
{
ServicePointManager.ServerCertificateValidationCallback = (snder, cert, chain, error) => true;
}
In Globasl.asax
I have:
<system.identityModel>
<identityConfiguration>
<certificateValidation certificateValidationMode="None"/>
</identityConfiguration>
</system.identityModel>
in Web.config.
My binding is:
<behaviors>
<serviceBehaviors>
<behavior name="CustomeBehavior">
<serviceAuthorization principalPermissionMode="Custom">
<authorizationPolicies>
<add policyType="Security.BusinessAuthorizationPolicy, Security" />
</authorizationPolicies>
</serviceAuthorization>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="SecurityOff">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />
<bindings>
<basicHttpsBinding>
<binding name="BasicHttpsBinding" sendTimeout="00:05:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpsBinding>
</bindings>
I can't see where there can be an issue. Also I'm STILL able to call .svc methods without any problems from HomeController.
So, there is my question - What can it be and why this is happening after changes from http to https (or there are another reason)?
Edit:
Client set up:
public static ChannelFactory<IBusiness> CreateFactory()
{
var authorization = new Authorization()
{
Key = GlobalConfig.BusinessAuthorizationKey
};
AddressHeader header = AddressHeader.CreateAddressHeader(authorization);
var address = new EndpointAddress(new Uri(ClientConfig.BusinessServiceEndpoint), header);
var channel = new ChannelFactory<IBusiness>(address.ResolveBinding(), address);
var bind = Helper.ResolveBinding(address);
if (bind is BasicHttpBinding)
{
var bindings = bind as BasicHttpBinding;
bindings.MaxBufferPoolSize = 2147483647;
bindings.MaxBufferSize = 2147483647;
bindings.MaxReceivedMessageSize = 2147483647;
bindings.MessageEncoding = WSMessageEncoding.Text;
bindings.ReaderQuotas.MaxArrayLength = 2147483647;
bindings.ReaderQuotas.MaxBytesPerRead = 2147483647;
bindings.ReaderQuotas.MaxDepth = 2147483647;
bindings.ReaderQuotas.MaxNameTableCharCount = 2147483647;
bindings.ReaderQuotas.MaxStringContentLength = 2147483647;
bindings.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
channel.Endpoint.Binding = bindings;
}
else
{
var bindings = bind as BasicHttpsBinding;
bindings.MaxBufferPoolSize = 2147483647;
bindings.MaxBufferSize = 2147483647;
bindings.MaxReceivedMessageSize = 2147483647;
bindings.MessageEncoding = WSMessageEncoding.Text;
bindings.ReaderQuotas.MaxArrayLength = 2147483647;
bindings.ReaderQuotas.MaxBytesPerRead = 2147483647;
bindings.ReaderQuotas.MaxDepth = 2147483647;
bindings.ReaderQuotas.MaxNameTableCharCount = 2147483647;
bindings.ReaderQuotas.MaxStringContentLength = 2147483647;
bindings.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
channel.Endpoint.Binding = bindings;
}
return channel;
}
I suppose You'll need to get valid certificate anyway. In meantime you may try to create self-signed certificate using info from powershell
get-help about_signing
Also you'll need to add certificate to IIS
Managed to deal with it.
I simply added
ServicePointManager.ServerCertificateValidationCallback = (snder, cert, chain, error) => true;
in factory creation. This thing has never refreshed after one call before, that's the reason I was getting this error, when everything seemed fine.
I have a program which have a wcf service to communicate with other module. I'd like to implement custom authorization and authentication. Sorry for bad code. Here is it:
Server:
Config:
<behaviors>
<serviceBehaviors>
<behavior name="managementMexBehavior">
<serviceMetadata httpGetEnabled="True" httpGetUrl="http://localhost:7538/management/mex"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
<serviceDiscovery>
<announcementEndpoints>
<endpoint kind="udpAnnouncementEndpoint"/>
</announcementEndpoints>
</serviceDiscovery>
</behavior>
</serviceBehaviors>
</behaviors>
<binding name="managementServerBindingConfig" closeTimeout="00:10:00"
openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
transferMode="Buffered" maxReceivedMessageSize="65535">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
Code
var binding = new NetTcpBinding("managementServerBindingConfig");
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
string address = _c24ServerAdminSettings.ManagementWebServerAddress;
ServiceEndpoint endpoint = Host.AddServiceEndpoint(ServiceInterface, binding, address);
endpoint.Name = "C24ServerAdminManagementEndpoint";
var parametrInspector = new OperationParametrInspector();
var errorHandler = new DispatcherErrorHandler();
errorHandler.OnHandleError += errorHandler_OnHandleError;
var behavior = new EnpointDispathcherBehavior(parametrInspector, errorHandler);
endpoint.Behaviors.Add(behavior);
//ServiceCredentials
ServiceCredentials scb = Host.Description.Behaviors.Find<ServiceCredentials>();
if (scb == null)
{
scb = new ServiceCredentials();
Host.Description.Behaviors.Add(scb);
}
scb.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom;
scb.UserNameAuthentication.CustomUserNamePasswordValidator = new PasswordValidator(_dataManager);
scb.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, "localhost");
//ServiceAuthorizationBehavior
ServiceAuthorizationBehavior sab = Host.Description.Behaviors.Find<ServiceAuthorizationBehavior>();
if (sab == null)
{
sab = new ServiceAuthorizationBehavior();
Host.Description.Behaviors.Add(sab);
}
sab.PrincipalPermissionMode = PrincipalPermissionMode.Custom;
sab.ExternalAuthorizationPolicies = new ReadOnlyCollection<IAuthorizationPolicy>(new[]
{
new AuthorizationPolicy()
});
Client:
Config:
<binding name="C24ServerAdminManagementEndpoint" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
<endpoint address="net.tcp://localhost:60001/Management/" binding="netTcpBinding"
bindingConfiguration="C24ServerAdminManagementEndpoint" contract="C24ServerAdminManagement.IManagementWebService"
name="C24ServerAdminManagementEndpoint">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
Code:
ManagementWebServiceClient ds = new ManagementWebServiceClient("C24ServerAdminManagementEndpoint", _managementServiceAddress);
ds.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
ds.ClientCredentials.UserName.UserName = UserName;
ds.ClientCredentials.UserName.Password = Password;
ds.Open();
This work pretty well with localhost. But when I set computer Ip address. Client trying to connect to service, service respond and exception occurs.In exception said that response received from DNS(localhost) while we wait from DNS(192.168.0.1). But 192.168.0.1 is local address.
I was having the same problem "...everything OK if the client and host are on the same machine, but if the Host and Client are on separate machines I get exceptions errors".
This is what solved the problem for me: My internet connection settings used a proxy server. I changed the IE options for the LAN settings to Bypass proxy server for local addresses and Do not use proxy server for addresses beginning with: http:\\host-ip-here
Good luck.
The problem was in dns identity. I used localhost certificate. And when i connected using direct IP service returned DNS from certificate.Actually adding dns identity in config should have fixed that problem. Maybe it didn't fix because i created endpoint in code and it load binding config but not endpoint. I rewrite code just a little
string address = _managementServiceAddress;
EndpointAddress epa = new EndpointAddress(new Uri(address), EndpointIdentity.CreateDnsIdentity("localhost"));
ManagementWebServiceClient ds = new ManagementWebServiceClient("C24ServerAdminManagementEndpoint", epa);
ds.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
ds.ClientCredentials.UserName.UserName = UserName;
ds.ClientCredentials.UserName.Password = Password;
It works fine.
I have webcam in a silverlight app. I capture the image and convert it to byte array and send to WCF service. Here is the image capture code:
MessageBox.Show("about to capture");
cs.CaptureImageAsync();
cs is the camera source and is configured correctly (as is the imagecapturecompleted event). On image capture completion, this code executes:
MessageBox.Show("Image Caputred");
var img = e.Result.ToImage();
var encoder = new PngEncoder();
Stream stream = img.ToStreamByExtension("png");
byte[] file = null;
if (stream.Length > 512000)
{
img = ExtendedImage.Resize(img, 240, new NearestNeighborResizer());
stream = img.ToStreamByExtension("png");
}
if (stream.Length < 512000)
{
BinaryReader binary = new BinaryReader(stream);
file = binary.ReadBytes((int)stream.Length);
MessageBox.Show("Stream read into file with length: " + file.Length);
}
else
{
MessageBox.Show("file size too large");
}
MessageBox.Show("Process done");
cs.Stop();
label1.Content = "and answer is : " + file!= null ? file.Length.ToString() : "ERROR";
ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client();
ServiceReference1.ITEM i = new ServiceReference1.ITEM { Image = file };
obj.DoWorkCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(obj_DoWorkCompleted);
obj.DoWorkAsync(i);
This is my web.config in the asp.net project that configures the service:
<system.serviceModel>
<services>
<service name ="AttendanceSystem.IService1" behaviorConfiguration="BasicHttpBinding_IService1">
<endpoint address="" binding="basicHttpBinding" contract="AttendanceSystem.IService1"/>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="BasicHttpBinding_IService1">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
And here is the reference to the service in the silverlight app
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:48886/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="default" />
</client>
</system.serviceModel>
Fiddler returns the following message on the call to my .svc service file:
HTTP/1.1 400 Bad Request
Server: ASP.NET Development Server/10.0.0.0
Date: Wed, 15 Jan 2014 09:17:26 GMT
X-AspNet-Version: 4.0.30319
Cache-Control: private
Content-Length: 0
Connection: Close
So what is going on?
UPDATE: the service seems to be working without error when I pass a smaller byte array (for example BitConverter.GetBytes(123) but fails when the image is sent which is clearly within the max limits)
Try to configure the binding server-side (maxReceivedMessageSize and reader quotas)
<bindings>
<basicHttpBinding>
<binding maxReceivedMessageSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
I have simple chat program using WCF service. One service use for server and another use for client. Those services connect to each other and call each other. For hosting server, I used a windows service and for client I host WCF service in a Windows app. After all I found that this code work on simple computer, but when move server service to another computer an exception raised and server can't connect to the client. I searched and try other ways.
I get a result:
*IF WCF SERVICE HOST IN WINDOWS APP U CAN'T CONNECT TO IT FORM ANOTHER COMPUTER.
*THIS CODE WORKED ONLY WHEN I USED TWO WINDOWS SERVICES (hosting WCF client service in a windows service)
But I want to know HOW hosting WCF service in windows app that can connect and work with another services?
This is my code
Client code:
Manager.cs
public delegate void UserInfoHandeler(string UserName);
public delegate void MessageHandeler(string Message);
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class Manager : IClientPoint
{
public void SendUserList(string[] users)
{
frmRoom.Members = users; // this method called by Server (WCF service which host in windows service)
//when server call this method I have an exception with SSPI
}
public void SendMessage(string message)
{
frmRoom.ReciveMessage = message; // this method called by Server (WCF service which host in windows service)
//when server call this method I have an exception with SSPI
}
FrmJoin frmJoin;
FrmRoom frmRoom;
ChatServerClient ServiceInvoker;
public string User
{
get;
set;
}
public void Run()
{
frmJoin = new FrmJoin();
frmJoin.LoginEvent += new UserInfoHandeler(frmJoin_LoginEvent);
ServiceInvoker = new ChatServerClient("WSHttpBinding_ChatServer", Settings.Default.ChatServerAddress);
frmJoin.ShowDialog();
}
void frmJoin_LoginEvent(string UserName)
{
frmRoom = new FrmRoom();
frmRoom.SendMessageEvent += new MessageHandeler(frmRoom_SendMessageEvent);
frmJoin.LogoutEvent += new UserInfoHandeler(frmJoin_LogoutEvent);
User = UserName;
frmRoom.ReciveMessage = ServiceInvoker.Login(User, Settings.Default.ClientPointAddress);
frmRoom.ShowDialog();
}
void frmJoin_LogoutEvent(string UserName)
{
string message = ServiceInvoker.Logout(UserName, Settings.Default.ChatServerAddress);
}
void frmRoom_SendMessageEvent(string Message)
{
ServiceInvoker.SendMessage(User, Message);
} }
Client config:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_Config" closeTimeout="00:05:00"
openTimeout="00:05:00" receiveTimeout="00:10:00" sendTimeout="00:05:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<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>
<binding name="MyConfig" closeTimeout="00:10:00" openTimeout="00:10:00"
sendTimeout="00:10:00" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_Config"
contract="Host.IChatServer" name="WSHttpBinding_ChatServer">
</endpoint>
</client>
<behaviors>
<serviceBehaviors>
<behavior name="Room.Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="Room.Service1Behavior" name="Room.Manager">
<endpoint address="" binding="wsHttpBinding" contract="Room.IClientPoint" bindingConfiguration="WSHttpBinding_Config">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
http://PChost:8731/ClientPoint/
http://PCserver:8731/ChatServer/
Server code:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class ChatServer : IChatServer
{
Dictionary clients;
public ChatServer()
{
clients = new Dictionary<string, ClientInvoker>();
}
public string Login(string Username, string address)
{
try
{
ClientInvoker client = new ClientInvoker("WSHttpBinding_ClientPoint", address);
clients.Add(Username, client);
foreach (ClientInvoker clientinvoker in clients.Values)
clientinvoker.SendUserList(clients.Keys.ToArray());
}
catch (Exception e)
{
File.AppendAllText(#"c:\ServiceChatLog.txt", "Service trow Exeption \n");
File.AppendAllText(#"c:\ServiceChatLog.txt", e.ToString() + " \n");
}
return string.Format("Welcom {0}", Username);
}
public string[] GetListUser()
{
return clients.Keys.ToArray();
}
public void SendMessage(string userName, string ReciveMessage)
{
string message = string.Format("{0} : {1}", userName, ReciveMessage);
foreach (ClientInvoker clientinvoker in clients.Values)
clientinvoker.SendMessage(message);
}
public string Logout(string Username, string address)
{
clients.Remove(Username);
foreach (ClientInvoker clientinvoker in clients.Values)
{
clientinvoker.SendUserList(clients.Keys.ToArray());
clientinvoker.SendMessage(string.Format("{0} left ROOM", Username));
}
return string.Format("Godbye {0}", Username);
}
}
Server config:
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_Config"
contract="Room.IClientPoint" name="WSHttpBinding_ClientPoint">
</endpoint>
</client>
If you need to use 2-way communication, maybe you should take a look at WCF Duplex Services.
*IF WCF SERVICE HOST IN WINDOWS APP U CAN'T CONNECT TO IT FORM ANOTHER COMPUTER
This couldn't be further from the truth. You can check a few things:
The server's firewall -- you're using a non-standard port, 8731, are you sure it's allowed?
The address -- can you connect to that IP and Port from the client normally? Try using telnet or putty, or expose the WSDL on the server and hit it through a browser.
Security -- the client endpoint is using Windows authentication -- are the two machines on the same domain or is the same user configured on both servers?