WCF Web Service Method Names
I am completely new to web Services, so forgive me if this is obvious to everyone but myself.
I have created a WCF C# web service which is working well. I then created Java and a C# clients to consume the output, which are also working well.
What is bothering me is that I can't figure out how to control the name of the method created in the proxy. In the service, I have a method called getCategory, but in the generated client code (both in Java using Netbeans and in C# with VS) the corresponding method gets named getX003CCategoryX003EKBackingField().
Is it possible to control this name?
EDIT: Here is a snip from the service:
[OperationContract(Name="GetCategoryObject")]
UrlCategory2 GetCategoryObject(string URL);
And the Contract:
[DataMember(Name="getCategory")]
public string Category {
get;
set;
}
I am generating the code using the WSDL read automation in Eclipse and Visual Studio.
SECOND EDIT: This should have all of the relevant bits.
namespace MyService.ServiceContracts
{
[ServiceContract(Name = "ICategorizer", Namespace = "MyService.ServiceContracts", SessionMode = SessionMode.Allowed)]
public interface ICategorizer
{
[OperationContract(Name="GetCategoryObject")]
UrlCategory2 GetCategoryObject(string URL);
[OperationContract]
string getCa开发者_如何转开发tegoryAsString(string URL);
}
}
namespace MyService.DataContracts {
[Serializable]
public class UrlCategory2 {
[DataMember(Name = "getCategoryEn")]
public string CategoryEn {
get;
set;
}
[DataMember(Name = "getCategoryFr")]
public string PawsCategoryFr {
get;
set;
}
[DataMember(Name="getCategory")]
public string Category {
get;
set;
}
}
}
namespace MyService
{
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerSession, UseSynchronizationContext = false)]
public class MyService : ICategorizer
{
...
public UrlCategory2 GetCategory(string URL) {...}
...
public UrlCategory2 GetCategoryObject(string URL) {...}
}
}
[wsdl:operation name="GetCategoryObject"]
[soap:operation soapAction="MyService.ServiceContracts/ICategorizer/GetCategoryObject" style="document"/]
[wsdl:input]
[soap:body use="literal"/]
[/wsdl:input]
[wsdl:output]
[soap:body use="literal"/]
[/wsdl:output]
[/wsdl:operation]
[wsdl:operation name="GetCategory"]
[soap:operation soapAction="MyService.ServiceContracts/ICategorizer/GetCategory" style="document"/]
[wsdl:input]
[soap:body use="literal"/]
[/wsdl:input]
Post the code for your WCF Service, also how are you generating the proxy? Typically they are named the same in the proxy as they are in the service.
You can use [OperationContract(Name= "Foo")]
on your method (in the service) to specify a specific name.
Judging by your code snippets, I'm not clear exactly how you have this set up.
In the class where
[DataMember(Name="getCategory")] public string Category { get; set; }
is defined, do you also specify that class as a [DataContract]
?
It should typically look something like:
[ServiceContract]
public interface IMyService
{
[OperationContract(Name="GetCategoryObject")]
UrlCategory2 GetCategoryObject(string url);
}
public class MyService : IMyService
{
public UrlCategory2 GetCategoryObject(string url)
{
return new UrlCategory2();
}
}
[DataContract]
public class UrlCategory2
{
[DataMember(Name="getCategory")]
public string Category { get; set; }
}
I don't see how you are fitting Category into your service in your code snippet. Do you have something like:
[ServiceContract]
public interface IMyService
{
[OperationContract(Name="GetCategoryObject")]
UrlCategory2 GetCategoryObject(string url);
[DataMember(Name="getCategory")]
public string Category { get; set; }
}
If so, then that is probably your issue; WCF services (within the [ServiceContract] decorated class) don't typically have properties. It is better to just use methods. It is probably trying to map the getter and setter methods for the property to 2 separate service methods in the WSDL.
Maybe change it to:
[OperationContract]
string GetCategory();
[OperationContract]
void SetCategory(string category);
精彩评论