小编Mac*_*ckM的帖子

为什么我从WSDL调用返回System.InvalidOperationException但不是从同一个调用到另一个服务?

我已经创建了服务来获取各种客户的国家详细信息,但在托管服务时我得到了这个例外.我正在使用基本的http绑定.

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.InvalidOperationException: An exception was thrown in a call to a 
WSDL export extension:   
  System.ServiceModel.Description.DataContractSerializerOperationBehavior
  contract: http://tempuri.org/:IReferenceDataService ----> 
     System.Runtime.Serialization.InvalidDataContractException: 
     Type 'Pariwaar.BusinessObject.CountryBO' cannot be serialized. 
     Consider marking it with the DataContractAttribute attribute, 
     and marking all of its members you want serialized with the 
     DataMemberAttribute attribute. See the Microsoft .NET Framework 
     documentation for other supported types.
   at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(String message, Type type)
   at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Int32 id, RuntimeTypeHandle typeHandle, Type type)
   at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation(Int32 id, RuntimeTypeHandle typeHandle, …
Run Code Online (Sandbox Code Playgroud)

wcf

15
推荐指数
1
解决办法
2万
查看次数

除非还指定了TOP或FOR XML,否则ORDER BY子句无效

我得到"ORDER BY子句在视图,内联函数,派生表,子查询和公用表表达式中无效,除非还指定了TOP或FOR XML." 以下代码出错.我最初有两张桌子,ADSAREAS和CATEGORIES.当我删除CATEGORIES表时,我开始收到此错误.

    Select Case SIDX  
     Case "ID" : SQLCONT1 = " AdsAreasID"
     Case "Page" : SQLCONT1 = " AdsAreasName"
     Case Else : SQLCONT1 = " AdsAreasID"  
End Select   
Select Case SORD  
     Case "asc" : SQLCONT2 = " ASC"
     Case "desc" : SQLCONT2 = " DESC"
     Case Else : SQLCONT2 = " ASC"  
End Select   
''# search feature --->
Select Case SEARCHFIELD  
     Case "ID" : SQLSFIELD = "AND AdsAreasID"
     Case "Ads Areas" : SQLSFIELD = "AND AdsAreasName"
     Case Else …
Run Code Online (Sandbox Code Playgroud)

sql-server asp-classic

14
推荐指数
2
解决办法
5万
查看次数

不支持从define_method()定义的方法传递super的隐式参数

在" 使用Rails的敏捷Web开发 "(第三版)第537-541页中,它具有"自定义表单构建器"代码,如下所示:

  class TaggedBuilder < ActionView::Helpers::FormBuilder
    # <p> # <label for="product_description">Description</label><br/> # <%= form.text_area 'description' %> #</p>
    def self.create_tagged_field(method_name) 
      define_method(method_name) do |label, *args|
        @template.content_tag("p" , @template.content_tag("label" , label.to_s.humanize, 
        :for => "#{@object_name}_#{label}") + "<br/>" + super)
      end
    end
    field_helpers.each do |name| 
      create_tagged_field(name)
    end 
  end
Run Code Online (Sandbox Code Playgroud)

此代码不适用于Ruby 1.9.1.它返回错误如下:

implicit argument passing of super from method defined by define_method() is not supported. Specify all arguments explicitly. (ActionView::TemplateError)

我的问题是:我应该在代码中更改什么来解决这个问题?

ruby ruby-on-rails formbuilder ruby-1.9

12
推荐指数
2
解决办法
8527
查看次数

将字符串拆分为最大长度为X的片段 - 仅在空格处分割

我有一个很长的字符串,我想分成几行,最多X个字符.但是,只在一个空格(如果字符串中的某些字长于X字符,只需将其放入自己的部分).

我甚至不知道如何开始这样做......用Python来说

伪代码:

declare a list
while still some string left:
   take the fist X chars of the string
   find the last space in that
   write everything before the space to a new list entry
   delete everything to the left of the space
Run Code Online (Sandbox Code Playgroud)

在我编写代码之前,是否有一些python模块可以帮助我(我不认为pprint可以)?

python algorithm text python-3.x

12
推荐指数
1
解决办法
5585
查看次数

{%load static%}和{%load staticfiles%}:哪个更受欢迎?

我不确定它们的区别是什么,看起来它们都在起作用.我用Google搜索,似乎它们几乎是一样的.只是出于好奇,人们在现场使用哪一个?

我读过但仍然不知道何时使用哪个,以及该领域的哪个人使用.我的工作都适合他们.起初我以为它是加载静态文件夹,但它也适用于静态文件... -

django django-templates django-static django-staticfiles

12
推荐指数
1
解决办法
7717
查看次数

你如何从静态main()调用方法?

我有一个带有Main方法和功能的控制台应用程序.

如何从Main方法中调用函数?

我知道下面的代码不起作用

static void Main(string[] args)
{            
   string btchid = GetCommandLine();// GetCommandline is a mthod which returns a string
}
Run Code Online (Sandbox Code Playgroud)

.net c#

11
推荐指数
2
解决办法
6万
查看次数

如何从临时文件对象获取文件名?

我的目标是创建一个由 csv.writer 编写的临时文件,该文件将在上传到数据库时使用。上传完成后,我想删除该文件。

上传和删除部分不包含在这里,因为我还没有完全构建它,但我需要先完成这一部分。

import csv, io, tempfile

filename = tempfile.NamedTemporaryFile(suffix='.csv', delete=False)

file = io.StringIO(report_downloader.DownloadReportAsString(report, skip_report_header=False, skip_column_header=False, skip_report_summary=True))
reader = csv.reader(file)

with open(filename, 'w', encoding='utf8', newline='') as f:
    writer = csv.writer(f, delimiter=',')
    for row in reader:
        writer.writerows([row])     
Run Code Online (Sandbox Code Playgroud)

这样做产生的错误是:

Traceback (most recent call last):
File "aw-ad-performance-tempfile.py", line 99, in <module> get_api_report()
File "aw-ad-performance-tempfile.py", line 92, in get_api_report
with open(filename, 'w', encoding='utf8', newline='') as f:

OSError: [Errno 22] Invalid argument:'<tempfile._TemporaryFileWrapper object at 0x00000274FBED0FD0>'
Run Code Online (Sandbox Code Playgroud)

我尝试了几种不同的方法来解决该问题,并且我发现它需要一个文件名位于此处的字符串:

with open(filename, 'w', encoding='utf8', newline='') as f:
Run Code Online (Sandbox Code Playgroud)

是否可以使用 …

python csv temporary-files

11
推荐指数
1
解决办法
1万
查看次数

Google的OpenID标识符因"消费者"域名而异.如果域名需要更改,如何避免问题?

我目前正在测试一个OpenID实现,我注意到Google为不同的消费主机名/域名发送了不同的标识符,即使对于同一个用户也是如此.例如,localhost与请求站点127.0.0.1用于同一用户时发送的标识符相比,Google会在请求站点发送不同的标识符.

注意:我实际上没有使用公共域名对此进行测试,但我不明白为什么行为会有所不同.

我对谷歌行为的担忧是,如果我们以后选择更改我们的网站域名,那么用户将无法再使用Google的OpenId作为身份提供商登录该网站.这似乎是一个大问题.我错过了什么,或者所有OpenID消费网站都遇到了这个潜在的问题?

我也用MyOpenId对它进行了测试,但MyOpenId创建的标识符是固定的,所以这对他们来说不是问题.

openid identity dotnetopenauth

9
推荐指数
1
解决办法
3517
查看次数

当它被绑定到调用函数中的const引用时,它的返回值的生命周期如何扩展到调用函数的范围?

"如果从函数返回一个值(不是引用),那么将它绑定到调用函数中的const引用,它的生命周期将扩展到调用函数的范围."

所以:案例A.

const BoundingBox Player::GetBoundingBox(void)
{
    return BoundingBox( &GetBoundingSphere() );
}
Run Code Online (Sandbox Code Playgroud)

const BoundingBox从函数返回类型的值GetBoundingBox()

变体I :(将它绑定到const引用)

const BoundingBox& l_Bbox = l_pPlayer->GetBoundingBox();
Run Code Online (Sandbox Code Playgroud)

变体II :(将它绑定到const副本)

const BoundingBox l_Bbox = l_pPlayer->GetBoundingBox();
Run Code Online (Sandbox Code Playgroud)

两者都工作正常,我没有看到l_Bbox对象超出范围.(虽然,我在变体1中理解,复制构造函数未被调用,因此稍微好于变体II).

另外,为了比较,我做了以下更改.

案例B

BoundingBox Player::GetBoundingBox(void)
{
    return BoundingBox( &GetBoundingSphere() );
}
Run Code Online (Sandbox Code Playgroud)

与变体:我

BoundingBox& l_Bbox = l_pPlayer->GetBoundingBox();
Run Code Online (Sandbox Code Playgroud)

和II:

BoundingBox l_Bbox = l_pPlayer->GetBoundingBox();
Run Code Online (Sandbox Code Playgroud)

该对象l_Bbox仍然没有超出范围.如何"将它绑定到调用函数中的const引用,它的生命周期将扩展到调用函数的范围",真正将对象的生命周期延长到调用函数的范围?

我在这里错过了一些小事吗?

c++ memory const pass-by-reference

9
推荐指数
2
解决办法
2587
查看次数

为什么我的(新手)代码这么慢?

我正在学习python,并且遇到了这个我以前见过的模型模拟的例子.其中一个功能看起来不必要很长,所以我认为尝试提高效率是一种好习惯.我的尝试,虽然需要更少的代码,大约快1/60.是的,我做了60倍.

我的问题是,我哪里出错了?我已经尝试计算函数的各个部分,但没有看到瓶颈在哪里.

这是原始功能.这是一个人们生活在网格上的模型,他们的幸福取决于他们是否与大多数邻居一样.(这是谢林的隔离模型.)所以我们给一个人一个x,y坐标,并通过检查他们每个邻居的种族来确定他们的幸福.

def is_unhappy(self, x, y):

    race = self.agents[(x,y)]
    count_similar = 0
    count_different = 0

    if x > 0 and y > 0 and (x-1, y-1) not in self.empty_houses:
        if self.agents[(x-1, y-1)] == race:
            count_similar += 1
        else:
            count_different += 1
    if y > 0 and (x,y-1) not in self.empty_houses:
        if self.agents[(x,y-1)] == race:
            count_similar += 1
        else:
            count_different += 1
    if x < (self.width-1) and y > 0 and (x+1,y-1) not in …
Run Code Online (Sandbox Code Playgroud)

python performance profiler

9
推荐指数
1
解决办法
325
查看次数