Quick Start to WCF troubleshooting

Source: Internet
Author: User
Tags hosting web hosting ssl certificate server hosting

Http://msdn.microsoft.com/zh-cn/library/aa702636.aspx

This topic describes the most common problems, their solutions, and where to find more information about them.

Q: If my client is temporarily idle after the first request, sometimes I will receive messagesecurityexception during the second request. What happened?

There are two main reasons for the second request failure: (1) the session has timed out or (2) the Web server hosting the service is recycled. In the first case, the session is valid before the service times out. When the service fails to receive a request from the client within the specified time period (receivetimeout), the service terminates the security session. Subsequent client messages will cause messagesecurityexception. The client must re-establish a security session with the service to send messages or use a stateful security context token. With a stateful security context token, a security session can also prevent the Web server from being recycled. For more information about using a stateful security context token in a security session, see How to: create a stateful security context token for a security session. Alternatively, you can disable a secure session. When wshttpbinding is usedEstablishsecuritycontextSet propertyFalseTo disable a secure session. To disable a security session for another binding, you must create a custom binding. For more information about creating a custom binding, see How to: Use securitybindingelement to create a custom binding. Before applying any of these options, you must first understand the applicationProgramSecurity requirements.

Q: after about 10 clients interact with my services, my services begin to reject new clients. What happened?

By default, the service can have up to 10 concurrent sessions. Therefore, if the service is bound to a session, the Service accepts a new client connection until the number is reached. After that, the Service rejects the connection from the new client until one of the current sessions ends. You can support more clients in multiple ways. If your service does not require a session, do not use session binding. (For more information, see use sessions.) Another option is to increase the session limit by changing the value of the maxconcurrentsessions attribute to a number suitable for your environment.

Q: Can I load my service configuration somewhere outside the configuration file of the WCF application?

Yes. However, you must create a custom servicehost class and override the applyconfiguration method. In this method, you can call base to load the configuration first (if you want to load the standard configuration information), but you can also replace the configuration to load the system. Note that to load configurations from a configuration file different from the application configuration file, you must analyze the configuration file and then load the configuration.

The followingCodeExample: how to overrideApplyconfigurationMethod and directly configure the endpoint.

Public class myservicehost: servicehost
{
Public myservicehost (type servicetype, Params URI [] baseaddresses)
: Base (servicetype, baseaddresses)
{Console. writeline ("myservicehost constructor ");}

Protected override void applyconfiguration ()
{
String straddress = getaddress ();
Uri address = new uri (straddress );
Binding binding = getbinding ();
Base. addserviceendpoint (typeof (idata), binding, address );
}

String getaddress ()
{Return "http: // mymachine: 7777/myendpointaddress /";}

Binding getbinding ()
{
Wshttpbinding binding = new wshttpbinding ();
Binding. Security. mode = securitymode. None;
Return binding;
}
}
Q: my services and clients work very well, but why can't my clients work normally when they are on another computer? What happened?

Depending on the exception, there may be multiple problems:

  • You may need to change the client endpoint address to the host name instead of "localhost ".
  • You may need to open the application port. For more information, see firewall instructions in the SDK example.
  • For other possible problems, see the example topic running the samples in a workgroup and processing SS machines.
  • If the client uses Windows creden and the exception is securitynegotiationexception, configure Kerberos as follows.
    1. Add the identification creden to the terminal element in the app. config file of the client:
      <Endpoint
      Address = "http: // myserver: 8000/myservice /"
      Binding = "wshttpbinding"
      Bindingconfiguration = "wshttpbinding_iserviceexample"
      Contract = "iserviceexample"
      Behaviorconfiguration = "clientcredbehavior"
      Name = "wshttpbinding_iserviceexample">
      <Identity>
      <Userprincipalname value = "name@corp.contoso.com"/>
      </Identity>
      </Endpoint>
    2. Run the self-hosted service under the system or NetworkService account. You can run this command to create a command window under the System Account:
      At 12: 36/interactive "cmd.exe"
    3. The service is hosted under Internet Information Service (IIS). By default, IIS uses the service entity name (SPNs) account.
    4. Use setspns to register a new SPNs in the domain. Note that you must have a domain administrator to perform this operation.

For more information about the Kerberos protocol, see the security concepts used in WCF and:

    • Windows Authentication debugging Error
    • Use http. sys to register the Kerberos service principal name (which may be an English webpage)
    • Kerberos description (may be an English webpage)
Q: When I initiate a faultexception with an exception type <exception>, I always receive a regular faultexception type on the client, instead of a generic type. What happened?

We strongly recommend that you create your own custom error data type and declare it as a detailed information type in your error agreement. The reason is that the exception type provided by the system is used:

    • Create a type dependency that removes one of the most powerful service-oriented applications.
    • It cannot depend on exceptions serialized in standard mode. Some exceptions (such as securityexception) may not be serialized at all.
    • Disclose the details of the internal implementation to the client. For more information, see specifying and handling errors in agreements and services.

However, if you are debugging an application, You Can serialize the exception information and use the servicedebugbehavior class to return it to the client.

Q: When the reply does not contain any data, the return speed of the one-way operation and the request-reply operation seems to be basically the same. What happened?

If an operation is set to one-way, only the operation protocol accepts the input message without returning the Output Message. In WCF, when outbound data has been written to the network or an exception is thrown, all client calls will be returned. One-way operations work in the same way. If the service cannot be found, they can be triggered; or if the service is not ready to accept data from the network, they can be blocked. Generally, in WCF, this causes one-way calls to return to the client faster than the request-response speed; however, any situation that slows down outbound data transmission over the network will reduce the speed of one-way operations and request-response operations. For more information, see one-way services and access services using clients.

Q: I am using an X.509 Certificate for my service and get a system. Security. cryptography. cryptographicexception. What happened?

This usually happens after you change the user account used when the IIS auxiliary process is running. For example, in Windows XP, if you change the default user account ASPnet used when aspnet_wp.exe is running to a custom user account, you may see this error. If the private key is used, the process that uses the private key must have the permission to access the file that stores the private key.

If so, the account of the process must be granted the Read access privilege to the file containing the private key. For example, if the IIS auxiliary process runs under the Bob account, you must grant Bob read access to the files containing the private key.

For more information about how to grant access to a file containing the private key of a specific X.509 certificate to a correct user account, see how to make the X.509 Certificate accessible by WCF.

Q: I changed the first parameter of the operation from uppercase to lowercase, and now my client raises an exception. What happened?

The parameter name value in the Operation signature is a part of the protocol and case sensitive. Use the system. servicemodel. messageparameterattribute attribute to distinguish between local parameter names and metadata that describes client application operations.

Q: I am using one of my tracking tools and get an endpointnotfoundexception. What happened?

If the tracing tool used does not comply with the system-provided WCF tracing mechanism and receives an endpointnotfoundexception indicating that the address filter does not match, you need to use the clientviabehavior class to direct the message to the tracing utility, and let the utility redirect these messages to the service address.ClientviabehaviorClass changeViaAddressing header, independent from the end ReceiverToSpecifies the next network address. However, do not change the endpoint address when performing this operation. It is used to set upToValue.

The following code example shows a sample client configuration file.

 
<Endpoint
Address = http: // localhost: 8000/myserver/
Binding = "wshttpbinding"
Bindingconfiguration = "wshttpbinding_imycontract"
Behaviorconfiguration = "myclient"
Contract = "imycontract"
Name = "wshttpbinding_imycontract">
</Endpoint>
<Behaviors>
<Endpointbehaviors>
<Behavior name = "myclient">
<Clientvia viauri = "http: // localhost: 8001/myserver/"/>
</Behavior>
</Endpointbehaviors>
</Behaviors>
Q: What is the base address? How is it associated with an endpoint address?

Base Address isServicehostThe root address of the class. By default, if you add a servicemetadatabehavior class to your service configuration, the Web Service Description Language (WSDL) of all endpoints published by the host) will be from the HTTP base address, any relative address provided to the metadata behavior, and "? In WSDL. If you are familiar with ASP. NET and IIS, you will see that the base address is equivalent to a virtual directory.

Q: How do I publish multiple endpoints for a service?

To do this, you can:<Endpoint>Element Added to the application configuration file<Service>Or perform equivalent steps programmatically. For more information, see specify the endpoint address, how to: create a service endpoint in configuration, and how to: create a service endpoint in code.

Q: How do I know which bindings support different behaviors?

For more information about binding provided by the system and the functions they support, see binding provided by the system.

Q: How do I Configure standard binding for any attribute using different values?

For more information, see configure binding for the Windows Communication Foundation Service.

Q: Do I need to deploy my services to an HTTP server if I want to use HTTP for transmission?

No. The binding provided by the system includes multiple bindings that support HTTP transmission when used from any host application type. For more information about binding provided by the system and the functions they support, see binding provided by the system.

Q: What are the default behaviors of services bound with the standard?

This depends on the selected Standard binding. Generally, the default behavior of binding sessions is to create a new service instance for each new client. Subsequent calls from a special client will be routed to the associated service instance. For more information about binding provided by the system and the functions they support, see binding provided by the system.

Q: Is there a simple way to view the function-bound ing? For example, how can I determine which bindings support transactions and security?

Yes. See the binding provided by the system.

Q: How can I transfer a custom data type from a service to a client?

The data types passed between two endpoints must be serializable. The simplest and most interoperable serialization mechanism for services is to use the datacontractattribute and datamemberattribute classes. For more information about this serialization mechanism and other supported serialization mechanisms, see specifying data transmission in service agreements.

Q: When should I use the configuration file for configuration and when should I use code for configuration?

In order to use the application configuration file, developers can take over the runtime configuration decisions by the deployer, therefore, you can apply the decisions that should never be made by the deployer to the configuration in the product code. The deployer can be a single installer on your computer, or an enterprise administrator who uses the enterprise group policy to modify computer configuration files and locally modify and lock these files. For examples of the latter, see How to: Lock an endpoint in an enterprise.

Q: What should I know about well-designed services?

See design and implementation services.

Q: What information does the generated client code contain?

To learn about the generated client code, see understand the generated client code. For more information about the client architecture, see the client architecture.

Q: Why should I call the close method on the WCF client object?

By calling an object on the WCF ClientCloseThe client and service can properly end the conversation and recycle its associated resources. In addition, if you are using a session, callCloseIt may be the quickest way to determine whether the session has been faulty since the last call (this scheme is meaningful to the client application. For more information, see accessing services and examples of expected exceptions using a WCF client.

Q: Why is my service not running as I expected, even if the code looks normal?

If your service application is configured using the application configuration file, you should check the file to determine whether some configuration elements or attributes are Accidentally changing the execution behavior. In particular, the runtime behavior is very dependent on implementing the Protocol binding in the endpoint. Confirm in the configuration file that the binding can support the required functions as expected.

If the configuration file looks intact, you can use diagnostic functions (such as logging and tracing) to continue to check the running behavior of the application. For more information, see manage and diagnose.

Q: What is the best way to notify the client service of problems?

The best way to perform this operation is to add the faultcontractattribute class with a custom serializable error data type to the operation. When an operation encounters an error condition that can be detected by this class, this class will trigger a new faultexception, where the type parameter is a serializable error type. For more information, see specifying and handling errors in agreements and services.

Q: What information should be sent back to the client?

Only the information required by the service client is returned. As a service designer, you should only provide this part of information, instead of providing more information, to minimize disclosure of internal implementation details to unauthorized clients. This is why we strongly recommend that you do not return exception objects in a soap error. For more information, see specifying and handling errors in agreements and services.

Q: How does my client application detect that the connection to the service has been closed?

It can handle events that change the status of the communicationobject on the client channel. However, it depends on the implementation of the channel to notify you when the channel is closed or when an error occurs. For example, the nettcpbinding class can quickly notify you that the channel has been closed or has an error because the session lifetime is associated with the lifetime of the basic socket.

However, session bindings designed to protect applications from slight network interference, such as sessions provided by the reliablesessionbindingelement class, may not be notified when you try to recreate a session. For this reason, we recommend that you do not try to detect the disconnected connection directly.

Instead, sessions should be considered as dialogs. If the channel is opened, called several times, and the channel is successfully closed, it can be assumed that the channel is not accidentally closed. For more information about clients and sessions, see use sessions. For more information about channel-related exceptions on the bound client, see use a client to access the service. For information on handling exceptions by regular parties, see specifying and handling errors in agreements and services.

Q: How do I configure a Secure Socket Layer certificate for WCF Service Security?

See how to: use an SSL certificate to configure the port.

Q: How can I use the message Checker to record or modify a message?

See the following topic:

    • How to: Check and modify service messages
    • How: Check or modify client messages
    • Recommended settings for tracking and message logging
Q: How do I add an endpoint address with additional information?

When you need to add a complex endpoint address programmatically (for example, if you want to programmatically specify an endpoint Address class containing a specific header or identifier), you must perform the following operations:RelativeorabsoluteaddressIs a relative or absolute unified Resource Identifier (URI ):

 
// Do this:
Serviceendpoint E = myservicehost. addserviceendpoint (C, B, "relativeorabsoluteaddress ");
E. Address = new endpointaddress (E. Address. Uri,/* other info like headers */);
Q: When I try to generate a web hosting example, the generation fails because the directory, COPY command, or delete command fails. Why is this happening?

During the generation process, some examples of Web Hosting attempt to copy the compiled WCF Service binary file to the % systemdrive % \ Inetpub \ wwwroot \ servicemodelsamples folder. This is actually to deploy the service in IIS. If you run the SDK command prompt or the Visual Studio account does not have the permission to modify the folder, the generation will be interrupted. To correct this error, Perform one of the following operations:

    • Grant % systemdrive % \ Inetpub \ wwwroot modification permission to the account used in the Generation example
      Or
    • Run the SDK command prompt or Visual Studio as an administrator.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.