Web service is created in PHP im calling by adding a reference in C#
funcRequest aa = new funcRequest();
aa.param = "ZZ";
string z;
funcResponse a = new funcResponse();
z = a.result;
i created like this to call the web service from C# but looks its not giving any value back .. where am i wrong ?
You shouldn't be creating the response object yourself. You should be doing something like:
FuncRequest request = new FuncRequest("ZZ");
MyWebService service = new MyWebService();
FuncResponse response = service.DoSomething(request);
Obviously the exact details will depend on how you're connecting to the service, whether you're generating the proxy code etc, but basically you need to get something involved which represents the service itself.
You'll need to instantiate and make requests with the generated client proxy class or something similar, you can't just new up requests and responses and in this manner, you need to use and retrieve them, respectively. For instance, if your service reference was named MyService then you ought to have a MyServiceClient class available to you, so that:
using (var myServiceClient = new MyServiceClient())
{
var request = new MyServiceRequestType();
request.MyProperty = "zzz";
var response = myServiceClient.MakeRequest(request);
}
Related
I have a WCF service which has a method named ArchiveFile(string fileName) which basically archives files. I have created a proxy project using svcutil and added its reference created in my client application and is consuming the service as follows:
var binding = new WSHttpBinding { Security = new WSHttpSecurity() { Mode = SecurityMode.None } };
var address = new EndpointAddress(this.TargetUrl);
var fileService = new FileServiceClient(binding, address);'
I want to know how do I determine the Http Status Code (200 - OK or any other) for the WCF Service call.
We can get the http status code through WebOperationContext Class:
WebOperationContext statuscode = WebOperationContext.Current;
Console.WriteLine(statuscode.OutgoingResponse.StatusCode);
For more information about WebOperationContext,please refer to the following link:
https://learn.microsoft.com/en-us/dotnet/api/system.servicemodel.web.weboperationcontext?view=netframework-4.8
When generating a WCF client proxy using SvcUtil.exe, the generated code contains classes that represent the message contracts (e.g. ImportDocument & ImportDocument_Result).
How can I invoke WCF operations by sending an object of such a class as a request to the endpoint, without having to call into the operation method and supplying all parameters?
So instead of
var proxy = new WebService_PortClient("endpointConfigurationName");
string result = proxy.ImportDocument("aNumber", "aLocation", "aType", "aDescription");
I would like to:
var proxy = new WebService_PortClient("endpointConfigurationName");
ImportDocument request = new ImportDocument
{
Number = "aNumber",
Location = "aLocation",
Type = "aType",
Description = "aDescription"
};
var response = (ImportDocument_Result)proxy.Invoke(request);
string result = response.return_value;
The code above uses an Invoke method, but that method does not exist. Is there an available equivalent to such an Invoke method?
I have some problem on a WCF proxy class (not sure if it's the proxy or the service class), here is the context:
I have a WCF service that I consume on a web application, this service calls another service and then process the response to take it back to the web app. Here is the construction of that method
public CreateProjectResponse CreateNewProject(List<CreateProjectRequestProject> projects)
{
ServiceHelper helper = new ServiceHelper();
CreateProjectResponse response = helper.CreateNewProject(projects);
return response;
}
Everything is just fine up to the response object assignation. I have my correct list of "CreateProjectResponseProject" objects. The problem is that after the return statement I see that the service class is creating a NEW set of "CreateProjectResponseProject" objects as if it's calling the constructor again and assigning the default values (null in this case).
Does anyone have an idea what can be happening? I have been researching and don't seem to find any related solution. BTW... this process was working before, nothing have changed on the solution. Hope someone can help. Thanks!
EDIT: Here is the code for the helper class:
public class ServiceHelper
{
public CreateProjectResponse CreateNewProject(List<CreateProjectRequestProject> projects)
{
CreateProjectRequest request = new CreateProjectRequest();
CreateProjectResponse response = new CreateProjectResponse();
ProjectCreator create = new ProjectCreator();
WebServiceConfig configs = new WebServiceConfig();
request.Projects = projects;
configs.Password = "XXXXXXX";
configs.Username = "USER";
configs.RemoteAddress = "https://server/listener/connector";
configs.EndpoingConfig = "CreateProjectEndpoint";
try
{
response = create.CreateProject(configs, request);
}
catch (Exception ex)
{
string messageError = "unable to create project:" + ex.Message.ToString();
}
return response;
}
}
I was using the WCF service as an intermediate to communicate to another service, I removed the intermediate and called my helper class directly from the web application (with the proper endpoint config) and everything works fine now.
I have a WCF service Provided by csla. I want to consume this service in my MVC Project.I have create a object of service like below:
ClientServiceReference.WcfPortalClient obj =
new ClientServiceReference.WcfPortalClient();
obj.Open();
Csla.Core.ContextDictionary con = new Csla.Core.ContextDictionary();
var ClientType = client.GetType();
ClientCriteria criteria = new ClientCriteria { LoweredSubdomainName = hostname };
Csla.Server.Hosts.WcfChannel.FetchRequest request =
new Csla.Server.Hosts.WcfChannel.FetchRequest(ClientType, criteria,con);
var list = obj.Fetch(request);
Getting error as:
The best overloaded method match for Customer.ClientServiceReference.WcfPortalClient.Fetch(Csla.Server.Hosts.WcfChannel.FetchRequest) has some invalid arguments
That is because the documentation says that the Fetch method takes a CriteriaRequest. You provide it with a FetchRequest.
From the docs:
Fetch(CriteriaRequest) (Method)
Parameters
request
Type: CriteriaRequest
I have created a WCF service which has a callback. I have created a sample client which will subscribe to these callbacks. I have been using the ListBasedPublishSubscribe sample as a base for this. However when I try and setup the unique callback address in the client with this code
context = new InstanceContext(null, new MyClass());
client = new MyClient(context);
WSDualHttpBinding binding = (WSDualHttpBinding)client.Endpoint.Binding;
string clientcallbackaddress = binding.ClientBaseAddress.AbsoluteUri;
clientcallbackaddress += Guid.NewGuid().ToString();
binding.ClientBaseAddress = new Uri(clientcallbackaddress);
The third line fails because client.Endpoint.Binding.ClientBaseAddress is null. Should this not be null (I assume so for the sample to work) and why is this the case in my app? Have I forgotten to do something?