我有一个WCF服务,需要将应用程序ID参数传递给每个服务调用.目前我暴露的方法需要一个参数.我想尝试将此信息推送到Channel标头中.我的WCF使用Net.tcp托管.这是我的客户端代理代码:
public class CustomerClient : ClientBase<ICustomerBrowser>, ICustomerBrowser
{
public Customer Get(string ApplicationID, string CustomerId)
{
try
{
using (OperationContextScope _scope = new OperationContextScope(this.InnerChannel))
{
MessageHeader _header = MessageHeader.CreateHeader("AppID", string.Empty, ApplicationId);
OperationContext.Current.OutgoingMessageHeaders.Add(_header);
return Channel.Get(ApplicationId, CustomerId);
// return Channel.Get(CustomerId);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
(注释掉的行是我想要继续使用的).
服务器代码:
var _context = WebOperationContext.Current;
var h = _context.IncomingRequest.Headers;
Run Code Online (Sandbox Code Playgroud)
在_context对象中有私有方法包含我的标题,但在_context.IncomingRequest.Headers中公开我得到这个:
public class CustomerClient : ClientBase<ICustomerBrowser>, ICustomerBrowser
{
public Customer Get(string ApplicationID, string CustomerId)
{
try
{
using (OperationContextScope _scope = new OperationContextScope(this.InnerChannel))
{
MessageHeader _header = MessageHeader.CreateHeader("AppID", string.Empty, …Run Code Online (Sandbox Code Playgroud) 我有以下接口和实现:
public interface INew
{
string TestString { get; }
}
public class PurchaseOrder : INew
{
public string OrderNo { get; set; }
public string TestString
{
get { return "This is a test string"; }
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用以下代码反映对象的OrderNo一部分PurchaseOrder:
var props = p.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.FlattenHierarchy);
foreach (var prop in props)
{
Console.WriteLine(prop.Name);
}
Run Code Online (Sandbox Code Playgroud)
我的输出也返回了该TestString属性。我已经搜索了排除已实现的接口成员的方法,但只能找到包含它的项目。谁能告诉我如何排除这些项目?
我正在使用包含 / (%2f) 的参数调用 WebAPI 方法。如果我用没有这个字符的参数来调用它,它就可以正常工作。
按照此链接Escape characters in WebApi call中的建议,我尝试了以下操作,但没有任何区别。
<httpRuntime targetFramework="4.5.1" relaxedUrlToFileSystemMapping="true"/>
Run Code Online (Sandbox Code Playgroud)
我用来调用 WebAPI 方法的代码如下
var id = "AA/F1"; // This causes a problem of 404 not found
var workingId = "BB-F2"; // This works fine
using (var client = new HttpClient(new HttpClientHandler {AutomaticDecompression = DecompressionMethods.GZip}))
{
var uri = new Uri(string.Format("http://[testServer]/[Controller]/Get/{0}", WebUtility.UrlEncode(id)));
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
var response = client.GetAsync(uri).GetAwaiter().GetResult();
if (response.IsSuccessStatusCode)
return JsonConvert.DeserializeObject<ReturnType>(response.Content.ReadAsStringAsync().GetAwaiter().GetResult());
throw new Exception(response.ReasonPhrase);
}
Run Code Online (Sandbox Code Playgroud)
我只配置了一条路线 - 如下所示:
GlobalConfiguration.Configuration.Routes.MapHttpRoute("Default", "{controller}/{action}/{id}", new { id …Run Code Online (Sandbox Code Playgroud) 我有一个使用 ODP.Net 版本 12.2.1100 的项目。该项目在今天开业之前一直运行良好。以下代码行导致了错误:
using (var cn = new OracleConnection("User Name={userID}, etc, etc"))
Run Code Online (Sandbox Code Playgroud)
返回的错误是:
Value cannot be null.
Parameter name: path
内部异常
at System.Security.Permissions.FileIOPermission.CheckIllegalCharacters(String[] str, Boolean onlyCheckExtras)
到目前为止我已经尝试解决该问题:
我正在尝试调用通用方法。该方法的定义如下:
public System.Collections.Generic.IList<T> Query<T>(string query, [string altUrl = ""])
where T : new()
Run Code Online (Sandbox Code Playgroud)
这是来自 github 上的 SalesforceSharp 库。我正在尝试在此调用上创建一个额外的服务层,并且正在努力调用它。请参阅下面的我的代码。
public List<T> Query<T>()
{
//IList<Salesforce.Account> _returnList = null;
IList<T> _returnList = null;
Type _t = typeof(T);
SqlBuilder _sb = new SqlBuilder();
_sb.Table = _t.Name.ToString();
foreach (PropertyInfo p in _t.GetProperties()) _sb.Fields.Add(p.Name.ToString());
MethodInfo method = _Client.GetType().GetMethod("Query");
method = method.MakeGenericMethod(_t);
try
{
object[] _prms = new object[1];
_prms[0] = _sb.SQL;
_returnList = (IList<T>)method.Invoke(_Client, new object[] { _prms });
//_returnList = _Client.Query<Salesforce.Account>(_sb.SQL);
}
catch { } …Run Code Online (Sandbox Code Playgroud)