I want to transfer data from client services to server services but I don't want to transfer it as parameter in each call of service functions
I tried to insert the data in OutgoingMessageProperties, but I didn't get it on server side, I got an error: A property with the name 'Token' is not present,
why?
If I'm not allowed to use it why it has the Add function?
The protocol I'm using is net.tcp
Client Side:
GeneralServicesClient Ret = new GeneralServicesClient(Consts.WcfGeneralChannels.TcpIp);
using (OperationContextScope scope = new OperationContextScope(Ret.InnerChannel))
{
OperationContext.Current.OutgoingMessageProperties.Add("Token", Guid.NewGuid());
Ret.Func();
}
Server Side:
System.ServiceModel.ServiceSecurityContext identity = System.ServiceModel.ServiceSecurityContext.Current;
OperationContext context = OperationContext.Current;
MessageProperties messageProperties = context.IncomingMessageProperties;
string token = messageProperties["Token"].ToString();//throw error: A property with the name 'Token' is not present
You should put your service call inside the using.
GeneralServicesClient Ret = new GeneralServicesClient(Consts.WcfGeneralChannels.TcpIp);
using (OperationContextScope scope = new OperationContextScope(Ret.InnerChannel))
{
OperationContext.Current.OutgoingMessageProperties.Add("Token", Guid.NewGuid());
Ret.Do();
}
Related
I need to config proxy credential for GA4 Client library to pass it from http proxy server, unfortunately there isn't any rich documentation for this purpose on the web (or maybe I couldn't find them)
Google Analytics Data API(GA4)
using Google.Analytics.Data.V1Beta;
using System.Net;
// Config Proxy Credential
WebProxy proxy = new WebProxy([proxy_url], [bypass]);
proxy.Credentials = new NetworkCredential([username], [password]);
// Google Analytics configuration
BetaAnalyticsDataClient client = BetaAnalyticsDataClient.Create();
RunReportRequest request = new RunReportRequest
{
Property = "properties/" + propertyId,
Dimensions = { new Dimension{ Name="city"}, },
Metrics = { new Metric{ Name="activeUsers"}, },
DateRanges = { new DateRange{ StartDate="2020-03-31", EndDate="today"}, },
};
// Make the request
var response = client.RunReport(request);
I have tried to assign object proxy to BetaAnalyticsDataClient or RunReportRequest object but I can't find it and I don't know how to use proxy configuration for GA4 library.
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
I have a WebAapp on Azure that sends a request to Azure Relay. It should transfer to a listener on premises WCF HTTPS service hosted on IIS that requires basic authentication. How do I send authorization basic header for the onprem WCF service over the Azure Relay . How do I send ? example,
"Authorization": "Basic 239837987XYC"
I have used channel factory,
var ChannelFactory<Overview.MyChannel> cf;
var relayNamespace ="myrelaynamespace";
var relayListener = "myrelaylistener";
var endPointAddress = new EndpointAddress(ServiceBusEnvironment.CreateServiceUri("https", relayNamespace, relayListener));
cf = new ChannelFactory<Overview.ItServiceManagementAOChannel>(binding, endPointAddress);
ClientCredentials loginCredentials = new ClientCredentials();
loginCredentials.UserName.UserName = "onpremWCFusername";
loginCredentials.UserName.Password = "onpremWCFpassword";
cf.Endpoint.Behaviors.Add(new TransportClientEndpointBehavior
{
TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(ConfigurationManager.AppSettings.Get("WcfRelayKeyName"), ConfigurationManager.AppSettings.Get("WcfRelayKey"))
});
cf.Endpoint.Behaviors.Add(loginCredentials);
I get the Error: The value could not be added to the collection, as the collection already contains an item of the same type: 'System.ServiceModel.Description.ClientCredentials'. This collection only supports one instance of each type.
Parameter name: item
using (var ch = cf.CreateChannel())
{
try
{
var resp = ch.CreateTaskAsync(req).Result;
}
}
Try to specify the windows credential as client credential.
factory.Credentials.Windows.ClientCredential.UserName = "administrator";
factory.Credentials.Windows.ClientCredential.Password = "123456";
IService sv = factory.CreateChannel();
Feel free to let me know if the problem still exists.
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 a project that has a service reference to a web service. Is there a way from the codebehind to get the actual http address of the service reference?
Thanks
You could retrieve it from the client proxy that was generated for you:
using (var client = new ServiceReference1.MyServiceClient("*"))
{
string address = client.Endpoint.Address.Uri.ToString();
}
or if you are having multiple endpoints in your config file:
using (var client = new ServiceReference1.MyServiceClient("MyService"))
{
var address = client.Endpoint.Address.Uri.ToString();
}
Yes, the generated proxy will have a Url property.