using WCF service in mvc with csla - c#

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

Related

C# WCF Service Get Status Code in Client from One way Service

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

In Google.Apis.Pagespeedonline.v5 how to get all categories in one call?

I am using Google.Apis.Pagespeedonline.v5 (nuget) to perform the analysis on my site.
By performing the analysis directly from the API Explorer site you can perform the test on all five categories.
https://developers.google.com/speed/docs/insights/v5/reference/pagespeedapi/runpagespeed
However, using the dotnet api, the category parameter only accepts one CategoryEnum, so, I can only get the result in one category per request.
I wonder if it is possible to get all categories in a single request
var initializer = new Initializer()
{
ApiKey = "XXXXXXXXXXXXXXX",
BaseUri = "https://www.googleapis.com/pagespeedonline/v5/runPagespeed",
GZipEnabled = true
};
var service = new PagespeedonlineService(initializer);
var request = new RunpagespeedRequest(service, "https://www.google.com");
request.Category = CategoryEnum.Accessibility;
request.Locale = "pt";
request.Strategy = StrategyEnum.Desktop;
var response = request.Execute();
Well, you can do it this way:
GET https://pagespeedonline.googleapis.com/pagespeedonline/v5/runPagespeed?category=ACCESSIBILITY&category=PERFORMANCE&locale=pt&strategy=DESKTOP&url=https%3A%2F%2Fwww.google.com%2F&prettyPrint=true&key=[YOUR_API_KEY] HTTP/1.1
But in your situation maybe you can change base URL to look like:
BaseUri = "https://www.googleapis.com/pagespeedonline/v5/runPagespeed?category=ACCESSIBILITY&category=PERFORMANCE"
Give it a try this way

Invoke WCF proxy using message contract objects

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?

SOAP service on Java returns incorrect types in Response

I use a third-party server written in Java.
WSDL is taken with the style of rpc/literal.
Connection to the service is initialized as follows:
private static MLPortChannel GetMerlionClient()
{
BasicHttpsBinding binding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.MaxReceivedMessageSize = 4096000;
EndpointAddress adress = new EndpointAddress(new Uri(#"https://apitest.merlion.com/rl/mlservice3"));
ChannelFactory<MLPortChannel> factory = new ChannelFactory<MLPortChannel>(binding, adress);
factory.Credentials.UserName.UserName = mlLogin;
factory.Credentials.UserName.Password = mlPassword;
return factory.CreateChannel();
}
It is works correctly only for one method and returns the correct data type and the data.
When I call other methods, they returns error as:
"Can not convert an object of type " ... MLService3RLTest.CatalogResult [] " of the type " ... MLService3RLTest.ShipmentDatesResult []"
In this example return type must be ShipmentDatesResult[].
I tested the service via special tool. All requests and responses is correct and returned correct XML.
What may be the cause of this error? Perhaps something needs to be configured for SOAP service. Maybe some magic option with right value?
If, instead of referring to the service, make a web link which uses the technology of web services .Net FrameWork 2.0 what works
var client = new WpfApplication1.com.merlion.apitest.MLService();
var myCredentials = new System.Net.NetworkCredential(Логин, Пароль);
// Create a webrequest with the specified URL.
var url = "https://apitest.merlion.com/rl/mlservice3";;
client.Credentials = myCredentials.GetCredential(new Uri(url), "Basic");
textBox.AppendText(client.helloWorld("Привет"));
var ответ = client.getCatalog("N1");
var массив = new string[] { "" };
var rz = client.getItems("N10100", массив, "", 0, 2, "");
add
client.PreAuthenticate = true;

What's wrong with my web service client?

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);
}

Categories

Resources